-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathchallenge_5.html
47 lines (46 loc) · 2.51 KB
/
challenge_5.html
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
39
40
41
42
43
44
45
46
47
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>JS Basics: Coding Challenge V</title>
</head>
<body>
<h1>Coding Challenge V</h1>
<p>
Remember the tip calculator challenge? Let's create a more advanced version using everything we learned!<br/>
This time, John and his family went to 5 different restaurants. The bills were $124, $48, $268, $180 and $42.<br/>
John likes to tip 20% of the bill when the bill is less than $50, 15% when the bill is between $50 and $200, and 10% if the bill is more than $200.<br/>
Implement a tip calculator using objects and loops:
<ol>
<li>Create an object with an array for the bill values.</li>
<li>Add a method to calculate the tip.</li>
<li>
This method should include a loop to iterate over all the paid bills and do the tip calculations.
</li>
<li>
As an output, create:
<ol>
<li>A new array containing all tips, and</li>
<li>An array containing final paid amounts (bill + tip).</li>
</ol>
HINT: Start with two empty arrays [] as properties and then fill them up in the loop.
EXTRA AFTER FINISHING: Mark's family also went on a holiday, going to 4 different restaurants. The bills were $77, $375, $110, and $45.
Mark likes to tip 20% of the bill when the bill is less than $100, 10% when the bill is between $100 and $300, and 25% if the bill is more than $300 (different than John).
</li>
<li>
Implement the same functionality as before, this time using Mark's tipping rules.
</li>
<li>
Create a function (not a method) to calculate the average of a given array of tips.
HINT: Loop over the array, and in each iteration store the current sum in a variable (starting from 0). After you have the sum of the array, divide it by the number of elements in it (that's how you calculate the average).
</li>
<li>Calculate the average tip for each family.</li>
<li>Log to the console which family paid the highest tips on average.</li>
</ol>
GOOD LUCK! 😀
</p>
<p><em>Check the developer console for the log</em></p>
<script src="./scripts/challenge_5.js" type="text/javascript"></script>
</body>
</html>