coding challenge #2
// function expression
const calcTip = function (bill) {
return bill <= 300 && bill >= 50 ? 0.15 * (bill) : 0.2 * (bill);
// This reads as if bill is less than equal to 300 And And if bill is greater than equal
to 50 , then 0.15* bill , else 0.2* bill.
}
//console.log(calcTip(500)); // 100
const bills = [125, 555, 44]
const tips = [calcTip(bills[0]), calcTip(bills[1]), calcTip(bills[2])];
// Here we are invoking the function calcTip in an array format and the returned values
from the function is being stored in this tips variable that we have created.
console.log(tips)
//BONUS
const totals = [bills[0] + tips[0], bills[1] + tips[1], bills[2] + tips[2]];
//Here we are adding the bill and the tip in each case.
console.log(totals);



Comments
Post a Comment