I created a simple calculator
johnRestBill = [124, 48, 268, 180, 42]; //dollar
function tipCal(){
for(var i = 0; i < johnRestBill.length; i++){
if (johnRestBill[i] < 50) {
console.log(johnRestBill[i] * .2);
} else if (johnRestBill[i] >= 50 && johnRestBill[i] <= 200){
console.log(johnRestBill[i] * .15);
} else {
console.log(johnRestBill[i] * .1);
}
}
}
return tipCal();
I got the result of each index of johnRestBill array and now I want to make an array with the result.
So I made var tips = []
and typed tips.push(tipCal())
but it is not working and I don't know why...
To create
tips
, it would be much more appropriate to use.map
instead, and for that, you need a function thatreturn
s the calculated tip: