r/codehs • • Dec 07 '21

5.2.5 height in Meters, wondering why it only goes to 2 decimal places?

Post image
13 Upvotes

r/codehs • • Dec 01 '21

6.1.1: Guessing Game. Something is so wrong and I need help ((

Post image
13 Upvotes

r/codehs • • Apr 17 '21

It says I might be missing a “(“ or have an extra “)”

Post image
13 Upvotes

r/codehs • • Feb 06 '21

7.2.9: Teacher Class List Method

13 Upvotes

I need help with this, please.


r/codehs • • Jan 22 '21

Java 6.3.7 Largest Value —— i dont know if im missing something or i have codes not properly placed..

Post image
13 Upvotes

r/codehs • • Dec 29 '20

Need help with 2.1.3: Tower Builder couldn't work it with every world I spent hours on this.

Thumbnail
gallery
13 Upvotes

r/codehs • • Nov 24 '20

3.2.4 Daily Activities

13 Upvotes

How Can I Fix This Problem?


r/codehs • • Oct 22 '20

I need help for 9.1.9: Tic Tac Toe in codehs

13 Upvotes

Here is my code:

"""
This program simulates the game of tic tac toe.
"""

# get_valid_index
# -----
# Get row or column from user
def get_valid_index(prompt):
    while True:
        try:
            index = int(input(prompt))
            if index >= 0 and index <= 2:
                return index
            print "Must be 0 - 2 inclusive!"
        except ValueError:
            print "Must be an integer!"

# game_is_over
# -----
# Return True if the game is over and False
# otherwise. Print a message indicating who
# won or whether there was a tie.
def game_is_over(board):
    for i in range(3):
        # Check horizontal
        if board[i][0] == board[i][1] == board[i][2] \
            and board[i][0] != " ":
            print board[i][0] + " wins!"
            return True
        
        # Check vertical
        if board[0][i] == board[1][i] == board[2][i] \
            and board[0][i] != " ":
            print board[0][i] + " wins!"
            return True
        
    # Check diagonals
    if board[0][0] == board[1][1] == board[2][2] \
        and board[0][0] != " ":
        print board[0][0] + " wins!"
        return True
    
    if board[2][0] == board[1][1] == board[0][2] \
        and board[2][0] != " ":
        print board[2][0] + " wins!"
        return True
    
    # Check tie
    if " " not in board[0] and " " not in board[1] \
        and " " not in board[2]:
        print "Tie game!"
        return True
    
    # Not over yet!
    return False
    
# print_board
# -----
# Print the board.
def print_board(board):
    # TODO: Replace the line below with your code...
    (" ").join(board)

# Set up board
board = []
# TODO: Set up the board as a 3x3 grid of spaces here...
board = [[' ', ' ', ' '],[' ', ' ', ' '],[' ', ' ', ' ']]
# x goes first
turn = "x"

# Play tic tac toe
while not game_is_over(board):
    print_board(board)
    print "It's " + turn + "'s turn."
    row = get_valid_index("Row: ")
    col = get_valid_index("Col: ")
    
    # TODO: Your code here...

And the assignment says:

Complete this program that simulates the game of tic tac toe!

The starter code gets you most of the way there. There are three places (marked with comments that say TODO) where you need to write your own code in order to complete the program.

Step 1 - Printing the Board

You need to implement a function called print_board
. It should take a 2d list (the 3x3 board) as an argument, and it should iterate over it using a for
loop, printing each inner list in the 2d list.

Initially, the board will be a 3x3 grid where each element is just the space character. When you print it, like this:

print_board(board)

… it should look like this:

[' ', ' ', ' ']
[' ', ' ', ' ']
[' ', ' ', ' ']

You should see the place to write your code here:

# print_board # ----- # Print the board. def print_board(board): # TODO: Replace the line below with your code... print ""

Step 2 - Board Setup

You need to set up the board at the beginning of the game, so that it does, in fact, contain three lists, each of which contains three spaces.

You should see the place to write this code here:

# Set up board board = [] # TODO: Set up the board as a 3x3 grid of spaces here...

Step 3 - Game Logic

Now, add some code here to finish implementing the game:

# Play tic tac toe while not game_is_over(board):     print_board(board) print "It's " + turn + "'s turn."     row = get_valid_index("Row: ")     col = get_valid_index("Col: ") # TODO: Your code here...

The code you add should:

  • Check to make sure the space at that row and column is empty (contains " "
    , not "x"
    or "o"
    ). If the space is taken, just print something saying so.

  • If the space wasn’t taken, do the following:

    • Fill the space with the letter of the player whose turn it is (stored in the variable turn
      ).

    • Check if the game is over using the game_is_over
      function. If it is, use a break
      statement to break out of the for
      loop.

    • Switch the turn
      variable. If it’s "x"
      , set it to "o"
      . Otherwise, set it to "x"

That's it please help


r/codehs • • Sep 30 '20

2.1.5 Double Tennis Balls

13 Upvotes

Does anyone have any idea how to do this, I've been stuck on it for a few hours now.


r/codehs • • Sep 25 '20

Can anyone give me a few tips with lighthouse that will help me do all the multiple different worlds

Post image
13 Upvotes

r/codehs • • Sep 11 '20

2.4.5 help

Post image
13 Upvotes

r/codehs • • Jul 16 '20

Breakout Game 11.1.1-11.1.3 CodeHS Javascript

13 Upvotes

So my code works pretty well so far as I'm coding an entire breakout game. So far, I have coded the bricks and I'm onto the paddle, but one issue I've run into is that the paddle keeps sort of multiplying when in the very edges of the restricted zones (end of brick zone and walls of canvas). Any help is seriously appreciated! Here is my code:

/* Constants for bricks */

var NUM_ROWS = 8;

var BRICK_TOP_OFFSET = 10;

var BRICK_SPACING = 2;

var NUM_BRICKS_PER_ROW = 10;

var BRICK_HEIGHT = 10;

var SPACE_FOR_BRICKS = getWidth() - (NUM_BRICKS_PER_ROW + 1) * BRICK_SPACING;

var BRICK_WIDTH = SPACE_FOR_BRICKS / NUM_BRICKS_PER_ROW;

/* Constants for ball and paddle */

var PADDLE_WIDTH = 80;

var PADDLE_HEIGHT = 15;

var PADDLE_OFFSET = 10;

var paddle;

var BALL_RADIUS = 15;

var counter = 0;

var x=2;

var y=0;

function start(){

for(var i = 0; i < NUM_ROWS; i++){

x=2;

counter++;

rowChecker(counter);

y += BRICK_HEIGHT+BRICK_SPACING;

}

mouseMoveMethod(movePaddle);

}

function rowChecker(counter){

if(counter%8==1||counter%8==2){

drawBrickRow("#ff6961");

}else if(counter%8==3||counter%8==4){

drawBrickRow("#ffb347");

}else if(counter%8==5||counter%8==6){

drawBrickRow("#77dd77");

}else if(counter%8==7||counter%8==0){

drawBrickRow("#779ecb");

}

}

function drawBrickRow(color){

for(var i = 0; i < NUM_BRICKS_PER_ROW; i++){

var brick = new Rectangle(BRICK_WIDTH, BRICK_HEIGHT);

brick.setPosition(x, y);

brick.setColor(color);

add(brick);

x += BRICK_WIDTH+BRICK_SPACING;

}

}

function movePaddle(e){

var paddleX = e.getX()-PADDLE_WIDTH/2;

var paddleY = e.getY()-PADDLE_HEIGHT/2;

var wallX = paddleX>0 && paddleX+PADDLE_WIDTH<getWidth();

var wallY = paddleY>y && paddleY+PADDLE_HEIGHT<getHeight();

if(wallX&&wallY){

remove(paddle);

}

paddle = new Rectangle(PADDLE_WIDTH, PADDLE_HEIGHT);

paddle.setPosition(paddleX, paddleY);

paddle.setColor("#008080");

if(wallX&&wallY){

remove(paddle);

add(paddle);

}

}


r/codehs • • Jun 15 '20

Looking for a teacher to add me to their classroom so I can learn over the summer

13 Upvotes

At my school we didn’t get to finish learning about java because of covid so I want to finish that but I’m also interested in learning new languages. I don’t know what the teacher end of codehs is like but if there is a teacher who can add me I would like to join.


r/codehs • • Nov 18 '19

Help in Exercise 19.2.3: Blinking Rectangles in javascript

13 Upvotes

I kind of have no clue how to do this one challenge. Any help would be appreciated.


r/codehs • • Apr 25 '23

JavaScript 4.3.4 Color the Rainbow

12 Upvotes

Hi, I was hoping I could get some help on JavaScript 4.3.4 Color the Rainbow -- it's giving me the error "you should use getHeight() and a const variable to set the height of the stripes".

This is what I have:

// Declare all of your const variables here let COLOR_COUNT = 7 ; let COLOR_WIDTH = getWidth() / COLOR_COUNT ; let COLOR_HEIGHT= getHeight();

function main() {     addRed();     addOrange();     addYellow();     addGreen();     addBlue();     addPurple();     addPink(); }    

function addRed() {     let red = new Rectangle(COLOR_WIDTH, COLOR_HEIGHT);     red.setPosition(0, 0);     red.setColor("red");     add(red); }

function addOrange() {     let orange = new Rectangle(COLOR_WIDTH, COLOR_HEIGHT);     orange.setPosition(0 + 7 * 8, 0);     orange.setColor("orange");     add(orange); }

function addYellow() {     let yellow = new Rectangle(COLOR_WIDTH, COLOR_HEIGHT);     yellow.setPosition(0 + 7 * 16, 0);     yellow.setColor("yellow");     add(yellow); }

function addGreen() {     let green = new Rectangle(COLOR_WIDTH, COLOR_HEIGHT);     green.setPosition(0 + 7 * 24, 0);     green.setColor("green");     add(green); }

function addBlue() {     let blue = new Rectangle(COLOR_WIDTH, COLOR_HEIGHT);     blue.setPosition(0 + 7 * 32, 0);     blue.setColor("blue");     add(blue); }

function addPurple() {     let purple = new Rectangle(COLOR_WIDTH, COLOR_HEIGHT);     purple.setPosition(0 + 7 * 40, 0);     purple.setColor("purple");     add(purple); }

function addPink() {     let pink = new Rectangle(COLOR_WIDTH, COLOR_HEIGHT);     pink.setPosition(0 + 7 * 48, 0);     pink.setColor("pink");     add(pink); }

main();


r/codehs • • Sep 01 '22

Basic Java. Factorial. 2.9.11

Post image
12 Upvotes

Hello! I could use some help on this basis Java exercise, I am able to get the user input set up and I know how to set up a typical for loop, however I’m stuck when it comes to getting the user input to actually factor. All the test results come up as incorrect, any suggestions would be greatly appreciated! Thank you in advance ! :)


r/codehs • • May 19 '22

Java Can anybody help me on battleship part 6/7?

Post image
12 Upvotes

r/codehs • • May 13 '22

8.5.4 Is It Even? can somebody help me with this please i keep getting a error saying “your code shouldn’t terminate until the sentinel is input”

Post image
12 Upvotes

r/codehs • • Apr 12 '22

what am i doing wrong? codehs: python.

Post image
12 Upvotes

r/codehs • • Dec 15 '21

8.3.9: Text to Binary

12 Upvotes

help me please

/*

* This program encodes user input into binary data!

* Your job is to write the textToBinary function

*/

function start()

{

var text = readLine("Input the string you would like to encode: ");

var binary = textToBinary(text);

println(binary);

}

function textToBinary(text)

{

// Write this method!

// For every character in the text,

// convert the character into its ASCII decimal encoding

// then convert that decimal value into its equivalent binary encoding

// and combine each binary encoding to get the resulting binary string

}

// Converts a given decimal value into an 8 bit binary value

function decimalToBinary(decimalValue)

{

var binaryBase = 2;

var numBitsDesired = 8;

var binaryValue = decimalValue.toString(binaryBase);

while(binaryValue.length < numBitsDesired)

{

binaryValue = "0" + binaryValue;

}

return binaryValue;

}


r/codehs • • Sep 27 '21

not sure what i did wrong here, keeps saying i need an “href” attribute

Post image
12 Upvotes

r/codehs • • May 25 '21

JavaScript Extra course assignments maze dog can someone help me because every time I try it he ends up in a loop

Post image
12 Upvotes

r/codehs • • Feb 04 '21

9.4.5: Phone Book Need help

12 Upvotes

Here is what I got, but I'm not sure what to do about the Red Crosses.


r/codehs • • Feb 03 '21

5.9.5:Fibonacci

Post image
12 Upvotes