-
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! -
Complete the below function called
range
that takes two integers as parameters,start
andend
, and returns an array containing all the whole numbers between them starting withstart
and up toend
(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.
-
Given the following array of
people
, write a function that, when passedpeople
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.
Last active
October 19, 2020 21:36
-
-
Save mmeigooni/3398ad73a3d1a35d3196d36d42940b9c to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
// 1
function billTotal(subtotal) {
var tip = subtotal * 0.15;
var tax = subtotal * 0.095;
return subtotal + tip + tax;
}
//2
function range(start, end) {
var array = [];
var n = end - start;
if (n > 0) {
for (i=0, i < n, i++) {
array[i] = start + i;
}
}
return array;
}
//3
function longestName(people) {
for (let i of people) {
var objName = people[i];
for ( var j in objName) {
var lenFullName = 0;
var partName = objName[j];
lenFullName += partName.length;
}
}
}