Skip to content

Instantly share code, notes, and snippets.

@biglovisa
Created May 4, 2017 18:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save biglovisa/063391d11804f688890afe618a358428 to your computer and use it in GitHub Desktop.
Save biglovisa/063391d11804f688890afe618a358428 to your computer and use it in GitHub Desktop.
Class 2: exercises

Functions: exercises

  • Answer the following questions with the person sitting next to you:

    • What does a function return by default?
    • What is the return keyword? What does it do?
    • Do you always have to give a function a name?
    • What is the difference between this: myFunctionName and myFunctionName()?
    • What is the function signature?
  • Create a function which takes the arguments name and jobTitle.

    • The function should return a string which is something like "Sam works as a Support Analyst".
  • Create a function called vacationPlanner

    • it takes three arguments: destination (String), budget (Number), totalCost (Number)
    • if the totalCost exceeds the budget, the function should return: "Sorry, but you need X$ more to go to Y." where X is the amount you are short, and Y is the destination you wanted to go to.
    • if the budget is equal to or more than the totalCost, return: "Pack your bags! You are going to Y with an extra spending budget of X$!" where Y is the destination, and X is how much you're budget exceeds the totalCost
    • if passed no arguments, it returns "Are you sure you just want to stay home?"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment