Skip to content

Instantly share code, notes, and snippets.

@san-sekhon
Forked from mmeigooni/mod1-assessment.md
Created July 15, 2017 07:15
Show Gist options
  • Save san-sekhon/834d29b722d301c83271cc6b5652f0e0 to your computer and use it in GitHub Desktop.
Save san-sekhon/834d29b722d301c83271cc6b5652f0e0 to your computer and use it in GitHub Desktop.

Exercises

  1. Write a function called billTotal that can be used to calculate the total to be paid at a restaurant -- including tip and tax -- given the subtotal (i.e. cost of food and drinks). We can assume that the tip will be 15% and tax will be 9.5%. Make sure that the tip does not include the tax!

  2. Complete the below function called range that takes two integers as parameters, start and end, and returns an array containing all the whole numbers between them starting with start and up to end (you can use a any loop. The function definition should look like this:

    function range(start, end) {
      // YOUR CODE HERE
    }

    You should be able to use it like so:

    range(0, 4); // => [0, 1, 2, 3]
    range(2, 7); // => [2, 3, 4, 5, 6]
    range(10, 10); // => []
    range(10, 2); // => []

    After you write your function, you can test it using the above inputs to make sure that it behaves correctly.

  3. Given the following array of people, write a function that, when passed people as a parameter, returns the person (that is, your function should return an object) with the longest name (first, middle & last).

    var people = [
      {name: {first: "Alyssa", middle: "P.", last: "Hacker"}, age: 26},
      {name: {first: "Ben", last: "Bitdiddle"}, age: 34},
      {name: {first: "Eva", middle: "Lu", last: "Ator"}, age: 40},
      {name: {first: "Lem", middle: "E.", last: "Tweakit"}, age: 45},
      {name: {first: "Louis", last: "Reasoner"}, age: 21}
    ];
    
    function longestName(people) {
      // TODO: Your code here
    }
    longestName(people);
    // => {name: {first: "Alyssa", middle: "P.", last: "Hacker"}, age: 26}

    HINT: It might be helpful to have a fullName function that, when given a person as a parameter, returns a person's full name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment