-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path[iteration for array map()] I Got Bills (6-9)]
48 lines (34 loc) · 1.33 KB
/
[iteration for array map()] I Got Bills (6-9)]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
* 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
*/
/*
* QUIZ REQUIREMENTS
* - Your code should have the variables `bills` and `totals`
* - Your `bills` array should call the `map()` method and store the return of `map()` in the `totals` array
* - Your `totals` array should be an array of numbers
* - Your code should print the `totals` array to the console
* - The output must be as described above.
*/
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
];
//totals is an array that has all the bill + 15% tip
var totals = bills.map(function(element){
element *= 1.15; //adding tip to each totals element
element = element.toFixed(2); //round it to 2 decimals
return Number(element); //with map you have return the result, make sure the array is numbers
});
console.log(totals);