WDI Fundamentals

WDI Fundamentals Unit 9


Your Turn Your Turn

Defining and Calling Functions 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!

Write the following functions:

  1. In the "JavaScript" panel in JS Bin, define a function recitePoem.

    • Inside the function, log "Roses are red, violets are blue." to the console.

      Hint: add console.log("Roses are red, violets are blue."); inside the function.

    • Call the recitePoem function in the "JavaScript" panel.

      Hint: make sure you use parentheses after the function name.

    • Hit the "Run" button in the "Console" panel and you should see "Roses are red, violets are blue." displayed in the "Console" panel.
  1. In the "JavaScript" panel in JS Bin, define a function playSong.

    • Inside the function, log "Cheer up sleepy Jean, Oh, what can it mean." to the console.
    • Call the playSong function.
    • Hit the "Run" button in the "Console" panel and you should see "Cheer up sleepy Jean, Oh, what can it mean." displayed in the "Console" panel.
  2. In the "JavaScript" panel in JS Bin, define a function twoByFour.

    • Inside the function, log 2 * 4 to the console.
    • Call the twoByFour function.
    • Hit the "Run" button in the "Console" panel and you should see 8 displayed in the "Console" panel.

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

Stuck? Check out the solutions for assistance.


Ready to move on? Here's the next lesson.