Guessing Game explainer


#1

The aim of this puzzle: Check another shell to see if the pea is under it and print a clue.

Walkthrough of the solution: The first line of code creates a variable called pea. It’s storing a random value – either 1, 2, or 3. This number represents which shell the pea is under. The if statement check if the value of pea and sees if it is NOT equal to 1. If pea is 2 or 3, then it prints, “Not under shell 1”.

You need to make a similar check for another shell – let’s do shell 3. We need another if statement below the original one but not inside of it. We want this check to happen after we’ve checked shell 1. To see if the pea is not under shell 3, we use pea !== 3. Now we know that the code inside the curly brackets of the if statement will only run if pea is not equal to 3. We can add a print() between the curly brackets that says, “Not under shell 3”.

Sample code solution:
(Tap below to reveal)

var pea = pickRandom([
  1,
  2,
  3
]);
if (pea !== 1) {
    print('Not under shell 1');
}
if (pea !== 3) {
    print('Not under shell 3');
}

JavaScript Concepts: Code Block (if statement), Calling Functions, Identifiers, Variable Declaration
Grasshopper Concepts: pickRandom(), print()


#3

What does !== Mean?? I think we should be told what dies that mean


#4

!== means ‘does not equal’. It checks if two values are not equal to each other. For example, since 5 is not equal to 4, 5 !== 4 would be true. Whereas 4 !== 4 would be false.

Another way to think of if, is that it’s the opposite of ===, which checks if two values are equal to each other.

H :slight_smile:


#5

I have been doing the exact thing on the explanation but I have been getting maximum call stack size exceeded


#6

Hi @Bryan_Chen,

This is a bug on our side — your code is correct! Sorry you’ve hit up against this issue, we’re still working to figure out what’s going wrong in these scenarios, so we can create a fix.

In the meantime, if you hard-close Grasshopper, re-open, then run your code again it should solve the puzzle. Let me know if that doesn’t fix things, though!

Thanks for flagging this,
H :slight_smile:


#7

I agree that this puzzle needed better explanation in the beginning. The hint wasn’t much help. This is meant for beginners… Should be explained to us like we have no previous understanding.


#9

Am also getting it wrong but is the same answer to yours.


#10

Why isn’t it working?


#11

The print('Not under shell 3') should be between the curly brackets {} of the if (pea !== 3).

The way your code is now, the 2nd If Statement will check if pea is not 3, but won’t do anything if that test is true. And the bottom print statement will always print.

–Frankie