WDI Fundamentals

WDI Fundamentals Unit 8


Your Turn Your Turn

Conditionals Exercise


Instructions

  1. Write the code to perform the actions listed below in the "JavaScript" panel in the JS Bin editor.
  2. If you don't see the JS Bin below, please refresh the page.
  3. Click "Run" to run the code in the "Console" panel.
  4. After clicking "Run", to check variable values, type the variable name in the "Console" panel on the right and hit enter/return.

JS Bin on jsbin.com

Let's get started!

In the exercise for the conditionals lesson, FizzBuzz, we wrote code that took an input, x, and set a new result value according to a specific set of rules.

This time, your challenge is to loop through every number from 1 to max, applying those exact same rules to each number and, before ending the loop, printing the result out in the console using the command console.log(result);.

For reference, if max is 20, the following should be displayed in the console:

1
2
fizz
4
buzz
fizz
7
8
fizz
buzz
11
fizz
13
14
fizzbuzz
16
17
fizz
19
buzz

Testing any number less than 20 should give you a subset of that result — in other words, if max is 5, we get the following:

1
2
fizz
4
buzz

Stuck? Check out the solutions to see what you can do.


Feeling confident? On to the quiz!