Function Exercise

Objective
In this class exercise students will demonstrate

  • how to write functions calculators.

  1. Fortune Teller
    1. Write a function named tellFortune that:
      1. takes 4 arguments: number of children, partner’s name, geographic location, job title.
      2. outputs your fortune to the screen like so: “You will be an X in Y, and married to Z with N kids.”
    2. Call that function 3 times with 3 different values for the arguments.
  2. Dog Age Calculator
    1. Write a function named calculateDogAge that:
      1. takes 1 argument: your puppy’s age.
      2. calculates your dog’s age based on the conversion rate of 1 human year to 7 dog years.
      3. outputs the result to the screen like so: “Your doggie is NN years old in dog years!”
    2. Call the function three times with different sets of values.
    3. Bonus: Add an additional argument to the function that takes the conversion rate of human to dog years.
  3. Lifetime Supply Calculator
    1. Write a function named calculateSupply that:
      1. takes 2 arguments: age and amount per day.
      2. calculates the amount consumed for rest of the life (based on a constant max age).
      3. outputs the result to the screen like so: “You will need NN to last you until the ripe old age of X”
    2. Call that function three times, passing in different values each time.

File name: LastName_FirstName-function.html
Upload the file to the Google Classroom > Functions.

Upload at the end of the day.
DUE: Friday, April 7, 2017

Advertisements