Exercise Tuesday

Goal: In the previous lessons, we learned:

  • Arguments to functions can be assigned to variables called parameters
  • The return keyword tells JavaScript to return the result from the line of code
  • Don't abbreviate variable names because it can get confusing after time has passed

Begin familiarizing yourself with writing custom functions in JSFiddle by completing the exercises detailed below.

Warm Up

  • How do we call a function?
  • What is a parameter, and how do we provide one to a function?
  • What is a return value? How do we tell our functions what value to return?
  • When do we need to parse integers?
  • What function is responsible for parsing integers?


Writing Custom Functions

Write custom function for each of the following prompts. Then, call the function providing the necessary parameters to see if your function successfully returns the correct value. And don't forget to parse integers when necessary!

  • Take somebody's name and say a greeting to them;
  • Write a function to subtract two numbers;
  • Now one to multiply two numbers. Then create a new function called threeTimes to multiply three numbers together.
  • Now write one to divide two numbers. Then write a new function called remainder to find the remainder of two numbers.
  • Prompt the user to enter their age, another prompt to enter their name and another prompt to enter their favorite food. Pass these as arguments to a function that returns a sentence combining all of this information. Then display the returned string with an alert.

Lesson 30 of 65
Last updated May 23, 2022