Last active
February 19, 2021 10:23
-
-
Save desinas/26acc3e96592df9ce4791cd35b073caa to your computer and use it in GitHub Desktop.
I got bills Quiz (6-9) of Udacity FEWD
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Programming Quiz: I Got Bills (6-9) | |
* | |
* Use the .map() method to take the bills array below and create a second array | |
* of numbers called totals. The totals array should contains each amount from the | |
* bills array but with a 15% tip added. Log the totals array to the console. | |
* | |
* For example, the first two entries in the totals array would be: | |
* | |
* [57.76, 21.99, ... ] | |
* | |
* Things to note: | |
* - each entry in the totals array must be a number | |
* - each number must have an accuracy of two decimal points | |
*/ | |
var bills = [50.23, 19.12, 34.01, | |
100.11, 12.15, 9.90, 29.11, 12.99, | |
10.00, 99.22, 102.20, 100.10, 6.77, 2.22 | |
]; | |
var totals = bills.map(function(bill) { | |
bill = bill + (bill * 0.15); | |
bill = bill.toFixed( 2 ); | |
return Number(bill); | |
}); | |
console.log(totals); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
var bills = [50.23, 19.12, 34.01, 100.11, 12.15, 9.90, 29.11, 12.99, 10.00, 99.22, 102.20, 100.10, 6.77, 2.22];
var totals = bills.map(bill => Number((bill += 0.15*bill).toFixed(2)));
console.log(totals);