r/codehs • u/gigilakoha • May 07 '20
r/codehs • u/UsefulCauliflower2 • May 04 '20
7.3.4 Vertical lines
It keeps saying this is wrong,
function start(){ verticalLine(100,200); verticalLine(200,100); verticalLine(300,20); } function verticalLine(x,Position,Length){ var line= new Line (xPosition, xPosition,length); add(line); }
I’m pretty sure I’m doing something wrong but I’m not sure exactly what,
r/codehs • u/0d3stroyer • Apr 27 '20
5.10.4: Snake Eyes
Assignment:
"Write a program that rolls two dice until the user gets snake eyes. You should use a loop and a half to do this. Each round you should roll two dice (Hint: use the Randomizer!), and print out their values. If the values on both dice are 1, then it is called snake eyes, and you should break out of the loop. You should also use a variable to keep track of how many rolls it takes to get snake eyes.
Sample Run:
Rolled: 6 5 Rolled: 5 2 Rolled: 3 6 Rolled: 6 2 Rolled: 1 2 Rolled: 5 3 Rolled: 1 4 Rolled: 1 1 It took you 8 rolls to get snake eyes."My code:
var SENTINEL = 1;
function start(){
var diceOne;
var diceTwo;
while(true) {println("" + diceOne + "," + diceTwo);
diceOne = Randomizer.nextInt(1,6);
diceTwo = Randomizer.nextInt(1,6);
if (diceOne && diceTwo == SENTINEL){println("" + diceOne + "," + diceTwo);
break;
}
}}
What am I doing wrong here?
r/codehs • u/dan1511 • Apr 23 '20
7.2.9 ArrayList. Can anyone help me on this exercise. I try many times but it didn’t work. Please help me. I really need it. Thank you very much.
r/codehs • u/[deleted] • Apr 09 '20
Pygame Sandbox
May I please ask how to add a picture I can use to code in Pygame? I'm trying to do so in the CodeHS sandbox editor.
r/codehs • u/S1dSnap_God • Apr 08 '20
Can someone evaluate my codehs Midpoint karel solution(it doesnt use beepers and is very small code and worked for all worlds ). is it the most optimal way to solve or is there better solution?
function start(){
turnLeft();
while(frontIsClear()){move();
if(frontIsClear()){
move();
turnRight();
move();
turnLeft();
}
}
turnAround();
while(frontIsClear()){move();
}
putBall();
turnLeft();}
r/codehs • u/YarikPizdets • Mar 08 '20
C++ Arrays
I need help with understanding how I would be able to select a random value in an Array. After I have my random value I would like to set that value to 0 so I don't draw it again.
For example, I have a deck of cards and I can only draw the first card in the array that isn't a value of 0 (that has been drawn already).
I'm not sure if this makes sense but I can give more details if needed
r/codehs • u/ParkingObjective4989 • Sep 07 '25
Other Can’t find past assignments
I had used codehs last year and I want to see my past assignments but don’t see the class anymore. When I try and download the code from past assignments is just has the readme.txt and nothing else. Is it possible to get them still?
r/codehs • u/sucksAtRoboquest • Feb 03 '25
Can you help me I don’t know what’s wrong
Why does it keep saying un caught error I need to finish this soon I have a bit of an extension bc I joined late but I have until the end of the week to finish please help me
r/codehs • u/ScawedyCat • Sep 18 '24
Asking for help but giving bo information
I've noticed people cone on here to ask for help but just say "i need help with 10.3.9 ASAP"
Just saying it'd be so much easier to help if we had more info. These are some things that you could include:
the full instructions
test cases / error messages (if any)
programming language
name of the course
any code / pseudocode you have (even if its wrong)
I love helping people but it's impossible if i have no info at all.
r/codehs • u/Rolis-183 • May 13 '24
is this code 6.1.3 Circles in boxes please
Does anyone know how to make this code?
r/codehs • u/Unfair-Response117 • Apr 22 '23
Can someone PLEASE help find the error of my code?
I want to create a rainbow filter on a zebra image of code hs:
Here is what I have so far:
"// DESCRIBE YOUR FILTER HERE IN THIS COMMENT!
function customFilter(image) {
var pixels = image.getImageData();
var data = pixels.data;
for (var i = 0; i < data.length; i += 4) {
var red = data[i];
var green = data[i+1];
var blue = data[i+2];
// Swap the red and blue channels
data[i] = blue;
data[i+2] = red;
// Apply a red tint to the image based on the red channel value
red += 100;
if (red > 255) {
red = 255;
}
// Apply a green tint to the image based on the green channel value
green += 50;
if (green > 255) {
green = 255;
}
// Apply a blue tint to the image based on the blue channel value
blue += 150;
if (blue > 255) {
blue = 255;
}
// Set the new RGB values for the pixel
data[i] = red;
data[i+1] = green;
data[i+2] = blue;
}
image.setImageData(pixels);
return image;
}
/*********************************************
* You do not need to write any code below this line.
* This is starter code that sets up the image on the screen
* and calls your customFilter function.
* Feel free to read this code and learn how it works!
* Be careful though, if you modify this code the program may not
* work correctly.
*********************************************/
// Constants for the image
var IMAGE_URL = "https://codehs.com/static/img/zebra.jpg";
var IMAGE_WIDTH = 350;
var IMAGE_HEIGHT = 250;
var IMAGE_X = getWidth() / 2 - IMAGE_WIDTH / 2;
var IMAGE_Y = getHeight() / 2 - IMAGE_HEIGHT / 2;
// We need to wait for the image to load before modifying it
var IMAGE_LOAD_WAIT_TIME = 50;
function start() {
// Set up the image
var image = new WebImage(IMAGE_URL);
image.setSize(IMAGE_WIDTH, IMAGE_HEIGHT);
image.setPosition(IMAGE_X, IMAGE_Y);
// Add it to the canvas
add(image);
// Wait for it to load before applying the filter
setTimeout(function(){
customFilter(image);
}, IMAGE_LOAD_WAIT_TIME);
}"
the error I keep getting is "TypeError: image.getImageData is not a function. (In 'image.getImageData()', 'image.getImageData' is undefined) customFilter@3:34 u/73:21"
PLEASE HELP ME TO CORRECT my CODE!!!!!
r/codehs • u/goldcrack1e • Apr 06 '23
JavaScript Need help with JS 7.1.3: Fun Snake 4!
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)

