WDI Fundamentals

WDI Fundamentals Unit 10

Your Turn Your Turn

If you don't see the JS Bin below, please refresh the page.

This time around, you won't be given any starter code. Instead, you'll need to write some functions from scratch using JS Bin's editor, based on the descriptions given below.

JS Bin on jsbin.com


1) Write the code for the functions described below using JS Bin's JavaScript tab. 2) Click "Run" to run the code. 3) Try calling each function from the console tab. If you do not see the console tab, click the "Console" button at the top of the JS Bin window. Use different parameters to make sure the functions work as expected.

Let's get started!

Write the following functions:

  • sayHello, which accepts one parameter, name. It should return a greeting to a person using his or her name (i.e., "Hello, name").
  • areBothEven, which accepts two parameters, a and b. It should return true, if a and b are both even, or false, if they are not.
  • hotOrNot, which accepts one parameter, temp. It should return "hot", if temp is above 75 degrees, or "not hot", if it is not.
  • threeIfNull, which accepts one parameter, num. If num is null, it should return 3. Otherwise, it should return the value of num.
  • greatest, which accepts three parameters (a, b, and c), and returns the one with the greatest value. For example, greatest(5, 10, 1) would evaluate to 10.

Once you've written and tested all of these functions, go ahead and move on.

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

On to the next lesson!