Skip to content

Instantly share code, notes, and snippets.

@szemate
Last active July 22, 2022 11:02
Show Gist options
  • Save szemate/b56b88784047858158786229e9e6aa7d to your computer and use it in GitHub Desktop.
Save szemate/b56b88784047858158786229e9e6aa7d to your computer and use it in GitHub Desktop.
Functions exercises

Functions Exercises

Exercise 1

A club has the following members:

First name Last name Year joined
Jon Snow 2000
Arya Stark 2013
Tywin Lannister 1987
  1. Write a function that takes a first name, a last name and a joining year parameter, and returns a message as a string that congratulates a member for their membership anniversary. E.g. Jon Snow receives the message "Dear Jon Snow, thank you for being a member for 21 years!"
  2. Add a comment above your function to explain what it does.
  3. Call your function with each member of the club and log the results to the console.
  4. What's the difference between a return and console.log?
  5. When would you choose to use functions over the way we have been scripting so far?

Exercise 2

As a gift to long-term members, the club offers a 10% discount from the membership fee.

  1. Write a function that takes a price parameter and returns the input price reduced by 10%.
  2. Call your function with the annual membership fee of £100 and the monthly membership fee of £10 and log the results to the console.
  3. How would you modify the function if the annual membership fee is reduced by 10% but the monthly membership fee is only reduced by 5%?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment