The aim of this puzzle: To print out either 'Accepted'
or 'Sorry'
based on whether the ticket is valid or not.
Walkthrough of the solution: The ticket
variable randomly picks a string, either 'valid'
, 'fake'
, or 'expired'
. If the ticket
is 'valid'
, the code should print out 'Accepted'
. If the ticket
value is anything else, it should print out 'Sorry'
.
An if...else
will only run 1 of its code blocks {}
. If the test in the parentheses is true, the 1st block runs just like a normal If Statement. If the test is false, then only the else
block {}
will run.
Between the curly brackets {}
right after the else
, add print('Sorry')
.
Sample code solution:
(Tap below to reveal)
var ticket = pickRandom(['valid','fake','expired']);
print('Ticket is ' + ticket);
if (ticket === 'valid') {
print('Accepted');
} else {
print('Sorry');
}
JavaScript Concepts: Binary Expression (===), Calling Functions, Conditionals (if…else statement), Data Structures (Arrays), Identifiers, Variable Declaration
Grasshopper Concepts: pickRandom()
, print()