478,561 views
8 votes
8 votes
5.10.4: 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?

User Cynicalman
by
2.9k points

2 Answers

15 votes
15 votes

Final answer:

You are using incorrect syntax in the if statement. Instead of 'if (diceOne && diceTwo == SENTINEL)', use 'if (diceOne == SENTINEL && diceTwo == SENTINEL)'.

Step-by-step explanation:

In your code, you are using incorrect syntax in the if statement. Instead of writing 'if (diceOne && diceTwo == SENTINEL)', you should write 'if (diceOne == SENTINEL && diceTwo == SENTINEL)'. The '==' operator is used to compare the values of two variables, while the '&&' operator is used to perform a logical 'and' operation.

Here is the corrected code:

while (true) {
println(diceOne + "," + diceTwo);
diceOne = Randomizer.nextInt(1, 6);
diceTwo = Randomizer.nextInt(1, 6);
if (diceOne == SENTINEL && diceTwo == SENTINEL) {
println(diceOne + "," + diceTwo);
break;
}
}

User TJB
by
2.7k points
11 votes
11 votes

Answer:

You didn't specify what the function actually does. BTW, good luck coding, I love coding and it is lots of fun, just stick with it!

Step-by-step explanation:

User Jaleesa
by
3.3k points