WDI Fundamentals

WDI Fundamentals Unit 9

Your Turn

Take a look at the sample code in the JS Bin below. If you don't see the JS Bin, please refresh the page.

JS Bin on jsbin.com

This exercise may be familiar to some of you — your job is to write some code that, depending on the value of x, assigns one of several values to result:

  • If x is evenly divisible by 3 (for example, 3, 6, or 9), set result to "fizz."
  • If x is evenly divisible by 5 (for example, 5 or 10), set result to "buzz."
  • If x is evenly divisible by both 3 and 5 (for example, 0 or 15), set result to "fizzbuzz."
  • If x is not evenly divisible by either 3 or 5 (for example, 7), set result to x.

Don't remember how to determine if something divides evenly? Look back at Unit 3 (Expressions) and review the modulus (%) operator.

To test your code, set a value for x in the editor and click "Run." Did you get the result you expected? Try out several different values for x, just to be sure.

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

On to the next lesson!