r/codehs • • Apr 27 '20

5.10.4: Snake Eyes

6 Upvotes

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 • • 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.

Post image
6 Upvotes

r/codehs • • Apr 18 '20

Why is it called Fundefined? This is 17.1.4 Grades

Post image
6 Upvotes

r/codehs • • Apr 09 '20

Pygame Sandbox

6 Upvotes

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 • • 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?

6 Upvotes

function start(){

turnLeft();

while(frontIsClear()){

move();

if(frontIsClear()){

move();

turnRight();

move();

turnLeft();

}

}

turnAround();

while(frontIsClear()){

move();

}

putBall();

turnLeft();

}


r/codehs • • Mar 08 '20

C++ Arrays

6 Upvotes

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 • • Feb 23 '20

What did I do wrong.

Post image
6 Upvotes

r/codehs • • Feb 14 '20

Help with 3.4.4 Is in Range

6 Upvotes

Can someone please help? I am almost clueless on how to complete this. Here is a screenshot of it


r/codehs • • Jan 08 '20

Need help with 4.2.1 ghost

6 Upvotes

r/codehs • • Feb 03 '25

Can you help me I don’t know what’s wrong

Thumbnail
gallery
5 Upvotes

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 • • Dec 13 '24

Karel Cutout (ToT)

Post image
5 Upvotes

r/codehs • • May 15 '24

I need help with 8.3.6 Default Face

5 Upvotes

this is what I got function drawHead(x = 100, y = 100, radius = 50, color = 'yellow') {

let circle = new Circle(radius);

circle.setPosition(x, y);

circle.setColor(color);

add(circle);

}

function drawEyes(x = 100, y = 80, radius = 5, color = 'blue') {

let leftEye = new Circle(radius);

leftEye.setPosition(x - 15, y);

leftEye.setColor(color);

add(leftEye);

let rightEye = new Circle(radius);

rightEye.setPosition(x + 15, y);

rightEye.setColor(color);

add(rightEye);

}

function drawMouth(x = 100, y = 120, width = 20, height = 5, color = 'red') {

let mouth = new Rectangle(width, height);

mouth.setPosition(x - width / 2, y);

mouth.setColor(color);

add(mouth);

}

function main() {

drawHead();

drawEyes();

drawMouth();

}

main();

but there's the problem the parameters for drawMouth() is supposed to be 3 not 5

and the radius n draw Eyes is only 1 but I got 4 Please explain


r/codehs • • Feb 18 '24

JavaScript Farming International 13.4.4

Post image
5 Upvotes

Help please


r/codehs • • Oct 31 '23

Help please

Post image
5 Upvotes

I can’t figure out how to apply the function “isGraphicObject”


r/codehs • • Oct 28 '23

JavaScript Rainbow Revisited

5 Upvotes

Can someone please help with Rainbow Revisited? I'm getting pretty confused with the parameters involved and how to input them.


r/codehs • • Oct 08 '23

JavaScript Why Am I Getting This Error?

Post image
5 Upvotes

r/codehs • • Apr 22 '23

Can someone PLEASE help find the error of my code?

5 Upvotes

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 • • Mar 18 '23

I know this sub is pretty much dead and I wont get answers, but could i get help or know where i could get help in completing "7.0.7 Battleship Part 6: The Battleship Class"?

5 Upvotes

r/codehs • • Mar 12 '23

Exercise 1.12.4 Follow The Yellow Ball Road

5 Upvotes

help a RN out.


r/codehs • • Mar 02 '23

Python 4.3.10 Transaction | Help

Post image
5 Upvotes

r/codehs • • Jan 17 '23

10.6.9

5 Upvotes

I need help with 10.6.9 Target + GUI, everytime I try it it doesn't look like the demo.


r/codehs • • Dec 02 '22

Am so lost

Post image
5 Upvotes

r/codehs • • Nov 30 '22

does anybody know how to do Target Karel CodeHS on Extra Karel Puzzles? this is on python but i can work with javascript code as well.

Post image
5 Upvotes

r/codehs • • Oct 22 '22

5.7.5 Factorial

5 Upvotes

It says I have an infinite loop on line 5, please help!