Hola or Oi explainer

Aim of the puzzle: Edit an if statement.
Walk through of solution: If statements are used to run a block of code only if a certain condition is true. It looks like this:

if (x === 5) {

Inside the () is the test. It uses the equality operator === to check if x is equal to 5. If this is true, then the code inside the {} will run, and x will be printed to the console. If x is not 5, then the program will skip over the if statement, and the code inside the {} will not run.

In this puzzle, the value variable uses pickRandom to choose between the strings 'oi' and 'hola'. The variable is then printed to the console, so we can see which was picked.

The 1st if statement checks if value is equal to 'hola'. If this is true, then the string 'Hi in Spanish' will be printed.

The 2nd if statement will check if value === 'oi'. If this is true, then the string 'Hi in Portuguese' will be printed.

Sample code solution:

var value = pickRandom(['oi', 'hola']);

if (value === 'hola') {
    print('Hi in Spanish');
if (value === 'oi') {
    print('Hi in Portuguese');

Javascript Concepts: If Statements, Strings, Variables
Grasshopper Concepts: print(), pickRandom()

1 Like

It is not working. Everytime it show me a message to click on reset Button.

Where is this?

Hey there,

Your code is correct, but the puzzle is looking for a variable named value (which is in the starter code), and isn’t finding it because it’s been renamed to x.

Double tap on the x in var x and rename it back to value. That should solve the problem.

Hope this helps!

Hi Ben,

Thank you so much.

1 Like