Weather Bot explainer

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:


if (weather.includes('raining')) {

if (weather.includes('sunny')) {

if (weather.includes('snowing')) {

if (weather.includes('cloudy')) {

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

let weather = 'The weather will be ' + pickRandom(['sunny', 'rainy', 'cloudy', 'snowy']);

let grey = {
  red: 169,
  green: 169,
  blue: 169

Why is let gray = {
And every color 169?

By pick random whether shout print different colors, but how if every color is set to 169?

The pickRandom() is picking from ‘sunny’, ‘rainy’, cloudy’, and ‘snowy’
The second let function is defining the color gray, telling the computer exactly what color ‘gray’ is
if you could change that code, you could change what color ‘gray’ is