The aim of this puzzle: Print 'Correct!'
if you correctly guess the mystery number.
Walkthrough of the solution: The If Statement has 2 parts: the test and the body (the code inside the curly brackets {}
). The test is either true or false. The code in the body will only run if the code in the test is true. The test in this puzzle is myGuess === mysteryNumber
. That is only true if the value of myGuess
is the same as mysteryNumber
. If those values are the same, that means you’ve correctly guessed the mysteryNumber
, and you should print a congratulations message.
Between the curly brackets, add print('Correct!')
Sample code solution:
(Tap below to reveal)
var mysteryNumber = pickRandom(10);
var myGuess = 7;
if (myGuess === mysteryNumber) {
print('Correct!');
}
print('The mystery number was ' + mysteryNumber);
JavaScript Concepts: Binary Expression (+ concatenation), Assignments, Code Block (if statement)
Grasshopper Concepts: print()