Weather Bot explainer


#1

Aim of the puzzle: Use the .includes() function to check if a string matches part of another string.

Walk through of solution: When first opening the puzzle, you will see a print statement that prints out a variable called weather. This variable uses pickRandom to choose between four weather types (sunny, raining, cloudy, or snowing), and forms a string such as 'The weather will be sunny.' or 'The weather will be raining.'.

Below this line, there is a completed if statement. Inside the test of the if statement ( ), the .includes() function checks if the string 'raining' is in the variable weather. Inside the code block of the if statement { } is drawBox(blue). Therefore, if weather.includes('raining') is true, then the program will draw a blue box.

To complete the puzzle, add three more if statements, just like the first, for the other three weather types.

In the test of each if statement ( ), use the includes() function to check if a string (such as 'cloudy', 'sunny', or 'snowing') is in the variable weather. In the code block { } of each if statement, use the drawBox function to draw a box of another color.

Sample code solution:

print(weather);

if (weather.includes('raining')) {
    drawBox(blue);
}

if (weather.includes('sunny')) {
    drawBox(yellow);
}

if (weather.includes('snowing')) {
    drawBox(white);
}

if (weather.includes('cloudy')) {
    drawBox(grey);
}

Additional Code: (hidden code that runs before the puzzle’s code)

var weather = 'The weather will be ' + pickRandom(['sunny', 'raining', 'cloudy', 'snowing']);

Javascript Concepts: Variables, Strings, If Statements, Function Calls, .includes()
Grasshopper Concepts: print(), pickRandom(), drawBox()