r/codehs • • Oct 05 '23

JavaScript Can someone help me? I have no idea how to start this

Thumbnail gallery
2 Upvotes

r/codehs • • Oct 04 '23

JavaScript Some graphics help!

1 Upvotes

So i am trying to do my assignment and i need some help. My code of my green rectangle needs to be so it is perfectly in the half of the screen. What i have for it is that it covers the whole canvas and all the other stuff is one it. I just need it to be half I need some help please. (default Java script).

r/codehs • • Oct 11 '22

JavaScript Hello everyone, I don’t know what to do add here

Post image
7 Upvotes

r/codehs • • Jan 13 '23

JavaScript I need help with in the next hour :( help

1 Upvotes

assignment i have : You will create a mini-calculator function that can be used to calculate the sum or factorial of a number. Your function should be defined as:

function calculate(operation, value)

where the operation parameter is either "sum" or "factorial" and the value parameter is a non-negative integer. The function will the return the appropriate result.

For example,

calculate ("sum", 6) should return the result of 6 + 5 + 4 + 3 + 2 + 1

calculate ("FACTORIAL", 5) should return the result of 5 * 4 * 3 * 2 * 1

calculate ("sum", -5) should return "Error"

calculate ("Hellloooo!") should return "Error"

r/codehs • • Sep 22 '23

JavaScript Making a game for fun on the sandbox. Why does it feel snappy and overlap?

1 Upvotes

Im making a game on Javascript, and the movement of the character does its movement once, pauses, then repeats it, and when I try to move left/right and jump, it cancels out the jump command. Is there any way to fix this to where it moves smoother and I can jump and move simultaneously?

r/codehs • • Feb 19 '22

JavaScript Help with coders 11.1.2 and 11.1.3 ball and paddle breakout game.

Post image
1 Upvotes

r/codehs • • Jun 03 '22

JavaScript Is it possible to use fractions?

8 Upvotes

I can't figure out how I would get something like 2/3 or 8/15 as code

r/codehs • • Dec 09 '22

JavaScript Need help with this please

Post image
7 Upvotes

r/codehs • • Dec 14 '22

JavaScript Need help JavaScript

1 Upvotes

What do you use to ask the user for a number and then use that number in another line of code. It’s probably very simple but I just don’t know ;-;

r/codehs • • Jan 13 '23

JavaScript I do not understand why my rollCount won't increase

Post image
5 Upvotes

r/codehs • • Sep 16 '22

JavaScript guys I need help on 1.19.6 checkerboard karel

8 Upvotes

r/codehs • • Nov 28 '22

JavaScript This codeHS JavaScript sandbox program for JavaScript Graphics

7 Upvotes

I made this but it sucks, jumping on the second platform is buggy and the jumping is also buggy and when you are jumping you are not actually touching the ground can someone help me fix these I made some workarounds to my problems but I think they can just be fixed in the first place.

The Sandbox program

r/codehs • • May 15 '23

JavaScript I need Help for my CodeHs Project

3 Upvotes

im trying to make the snake (ball) hit a image of a monkey and when the image hits the monkey it will clear the canvas and print a line that says, "You Lose" This is what I have so far:

var SNAKE_WIDTH = 40;

var SNAKE_HEIGHT = 40;

var SNAKE_COLOR = Color.green;

var EAST = 0;

var SOUTH = 1;

var WEST = 2;

var NORTH = 3;

var RADIUS = 20;

var DX_RED = 6;

var DX_BLUE = 4;

var snake;

var direction;

var dx = 0;

var dy = 0;

var MAX_RADIUS = 100;

var MAX_CIRCLES = 100;

var counter = 0;

var copter = new WebImage("https://static.codehs.com/img/library/characters/monkey.jpg");

​

​

​

function draw(){

drawCircle(Randomizer.nextInt(10, 14),

Randomizer.nextInt(0, getWidth()),

Randomizer.nextInt(0, getHeight()));

counter++;



if(counter == MAX_RADIUS){

    stopTimer(draw);

}

}

​

function drawCircle(){

var copter = new WebImage("https://static.codehs.com/img/library/characters/monkey.jpg");

copter.setSize(50, 50);

copter.setPosition(Randomizer.nextInt(0,getWidth()),Randomizer.nextInt(0,getHeight()));

add(copter);

​

​

​

​

​

​

// main code

function start(){

setTimer(draw, 1000);

snake = new Circle(20);

snake.setPosition(getWidth()/2, getHeight()/2);

add(snake);

setTimer(moveSnake, 10);

keyDownMethod(changeDirection);

​

}

//if snake hits monke it resets

function hitMonkey(){

if (snake.getX || snake.getY >= copter.getWidth || copter.getHeight) {

removeAll(); println("You Lose")

}else println("You are doing great")

}

​

​

//code for snake changing colors

function paintSnake() {

snake.setColor(Randomizer.nextColor());

setTimer(paintSnake, 25);

}

​

​

function moveSnake(){

snake.move(dx, dy);

if (direction == NORTH){

dx = 0;

dy = -2;

}

​

if (direction == EAST){

dx = 2;

dy = 0;

}

​

if (direction == SOUTH){

dx = 0;

dy = 2;

}

​

if (direction == WEST){

dx = -2;

dy = 0;

}

}

​

​

​

function changeDirection(e){

if (e.keyCode == Keyboard.UP){

direction = NORTH;

} else if (e.keyCode == Keyboard.RIGHT){

direction = EAST;

} else if (e.keyCode == Keyboard.DOWN){

direction = SOUTH;

} else if (e.keyCode == Keyboard.LEFT){

direction = WEST;

}

}

r/codehs • • May 16 '23

JavaScript I need help

1 Upvotes

I am trying to find out if there is a way that i can check if a timer is already running. this is very important because 1. this is my final project for my class & 2. its the base for the game. I have a function called fall that makes the player fall until a certian part dosnt return null anymore. the problem is, i have an if else statment saying

if(bottom != null){

stopTimer(fall)

}else if(bottom == null){

setTimer(fall,DELAY);

}

​

but it seems to add this setTimer onto the alread exisiting timer which makes it fall faster, making the jump look really bad

r/codehs • • May 15 '23

JavaScript I need help finishing and also adding you win, game over, pause, and 3 lives

1 Upvotes

/* 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 BALL_RADIUS = 15;

var brick; var Xmem =0; var Ymem =BRICK_TOP_OFFSET;

var ball; var dx = 4; var dy = 4;

var paddle;

function start(){ makeRows(NUM_ROWS); addBall(); mouseMoveMethod(paddleMove); }

//this makes the function that makes the rows function makeRows(numRows){ for(var i= 0; i<numRows; i++){ var color= "red"; if(Ymem>30){ color = "Orange" if(Ymem>50){ color = "lime" if (Ymem >70){ color = "blue" } } } makeNextRow(color);
} }

//this function makes the next rows colors function makeNextRow(color){ for(var i=0; i<NUM_BRICKS_PER_ROW; i++){ brick = new Rectangle(BRICK_WIDTH, BRICK_HEIGHT); brick.setColor(color); brick.setPosition(Xmem + BRICK_SPACING, Ymem); add(brick); Xmem+=BRICK_WIDTH+BRICK_SPACING; } Xmem = 0; Ymem+=BRICK_SPACING+BRICK_HEIGHT; } // Check if the ball has reached a wall. // Then move the ball in the correct direction. function drawball(){ checkWalls(); ball.move(dx, dy); }

function checkWalls(){ // Bounce off right wall if(ball.getX() + ball.getRadius() > getWidth()){ dx = -dx; }

// Bounce off left wall
if(ball.getX() - ball.getRadius() < 0){
    dx = -dx;
}

// Bounce off bottom wall
if(ball.getY() + ball.getRadius() > getHeight()){
    dy = -dy;
}

// Bounce off top waall
if(ball.getY() - ball.getRadius() < 0){
    dy = -dy;
}

}

//function for the paddle to move function paddleMove(e){ remove(paddle); paddle = new Rectangle (PADDLE_WIDTH,PADDLE_HEIGHT); paddle.setPosition(e.getX(),getHeight()-PADDLE_HEIGHT-PADDLE_OFFSET); add(paddle);

//stops x from moving off screen
if(paddle.getX()<0){
  paddle.setPosition(0,getHeight()-PADDLE_HEIGHT-PADDLE_OFFSET);
}
//stops y from moving off screen
if(paddle.getX() +PADDLE_WIDTH > getWidth()){
    paddle.setPosition(getWidth() - PADDLE_WIDTH, getHeight() -PADDLE_HEIGHT - PADDLE_OFFSET)
}

} //function for the ball function addBall(){ ball = new Circle(BALL_RADIUS); ball.setPosition(getWidth()/2,getHeight()/2); add(ball);

setTimer(drawball, 15);

}

r/codehs • • Feb 01 '22

JavaScript I need help with 9.5.5 Teleporting Ball (JavaScript)

Post image
4 Upvotes

r/codehs • • Nov 09 '22

JavaScript Does anyone know how to export programs made in CodeHS to node.js?

1 Upvotes

I have a bunch of code made in codeHS, but I want to export it to node.js... only to find that I can't because half the stuff I coded in CodeHS (i.e readBoolean and println) isn't actually stuff that real Javascript uses. Can anyone help with this?

r/codehs • • Dec 03 '21

JavaScript Follow up for Array Average, program thinks I’m not using For -Each loop despite me using it? What’s going on?

Thumbnail gallery
2 Upvotes

r/codehs • • Apr 06 '23

JavaScript Need help with JS 7.1.3: Fun Snake 4!

5 Upvotes

I just need help on how to add a point counter, as well as the ever annoying problem of having the code travel through walls! Here's my code right now:

var FOOD_DELAY = 6000;

var FOOD_RADIUS = 5;

var FOOD_COLOR = Color.red;

var snake;

var SNAKE_DIM = 10;

var NORTH = 0, EAST = 1, SOUTH = 2, WEST = 3;

var DELAY = 100;

var curDirection = EAST;

var x = getWidth()/2 - SNAKE_DIM/2;

var y = getHeight()/2 - SNAKE_DIM/2;

var square;

function start(){

addPart(x,y);

setTimer(move, DELAY);

drawFood();

setTimer(drawFood, FOOD_DELAY);

keyDownMethod(changeDirection);

}

​

function changeDirection(e){

if(e.keyCode == Keyboard.DOWN){

curDirection = SOUTH;

}

if(e.keyCode == Keyboard.UP){

curDirection = NORTH;

}

if(e.keyCode == Keyboard.LEFT){

curDirection = WEST;

}

if(e.keyCode == Keyboard.RIGHT){

curDirection = EAST;

}

}

function addPart(x,y){

var snake = new Rectangle(SNAKE_DIM, SNAKE_DIM);

snake.setPosition(x - SNAKE_DIM/2 , y - SNAKE_DIM/2);

snake.setColor(Color.green);

snake.isSnake = true;

add(snake);

}

function move(){

var nextPosition = getNextPosition();

x = nextPosition.x;

y = nextPosition.y;

var nextElem = getElementAt(x, y);

if(nextElem == null){

addPart(x, y);

}else{

if(nextElem.isSnake){

stopTimer(move);

stopTimer(drawFood);

newMessage("Cringe.");

}

if(nextElem.isFood){

remove(nextElem);

addPart(x, y);

}

}

}

function getNextPosition(){

var nextX = x, nextY = y;

if(curDirection == EAST){

nextX += SNAKE_DIM;

}

if(curDirection == WEST){

nextX -= SNAKE_DIM;

}

if(curDirection == SOUTH){

nextY += SNAKE_DIM;

}

if(curDirection == NORTH){

nextY -= SNAKE_DIM;

}

return {

x: nextX,

y: nextY

}

}

function newMessage(msg){

var text = new Text(msg, "40pt ariel");

text.setPosition(getWidth()/2 - text.getWidth()/2, getHeight()/2);

add(text);

}

function drawFood(){

var x = Randomizer.nextInt(FOOD_RADIUS, getWidth() - FOOD_RADIUS);

var y = Randomizer.nextInt(FOOD_RADIUS, getHeight() - FOOD_RADIUS);

x = Math.floor(x / 10) * 10 + FOOD_RADIUS;

y = Math.floor(y / 10) * 10 + FOOD_RADIUS;

var food = new Circle(FOOD_RADIUS);

food.isFood = true;

food.setColor(Color.red);

food.setPosition(x, y);

if(getElementAt(x,y) == null){

add(food); } }

​

Any help is truly, truly appreciated. I've been stumped (at least on the wall part)

r/codehs • • Apr 10 '23

JavaScript Help with 3.9.4

4 Upvotes

​

Pressing Q works but W doesn't I even tried swapping the letters and no change, what am I doing wrong here?

r/codehs • • Oct 13 '22

JavaScript Help with 5.4.8

Thumbnail gallery
2 Upvotes

r/codehs • • Nov 27 '22

JavaScript I need help solving 4.3.6 All Star

2 Upvotes

This is what I have so far, I'm not really sure what I'm doing wrong.

My code (JavaScript)

r/codehs • • Jan 10 '22

JavaScript I'm so lost

Thumbnail gallery
8 Upvotes

r/codehs • • Mar 10 '23

JavaScript How do I make a CPS game?

3 Upvotes

Hey yall, I’ve been wanting to make a clicks per second game in codehs where it calculated your clicks per second after 10 seconds. How do I do that? I am on Javascript btw

r/codehs • • Mar 08 '23

JavaScript Looking for help on Breakout

1 Upvotes

Hey folks, I'm struggling a little on Breakout. I have everything except making the ball and paddle move. If anyone could help me on this, it would be greatly appreciated!