Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3075714

Browse files
src: Add solution to Coding Challenge 3
1 parent 34d6b50 commit 3075714

File tree

4 files changed

+55
-2
lines changed

4 files changed

+55
-2
lines changed

‎src/challenges/from-tutorial-1/1/index.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</head>
77

88
<body>
9-
<h1>TEST PAGE</h1>
9+
<h1>Coding Challenge 1</h1>
1010
</body>
1111

1212
<script src="index.js"></script>

‎src/challenges/from-tutorial-1/2/index.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</head>
77

88
<body>
9-
<h1>TEST PAGE</h1>
9+
<h1>Coding Challenge 2</h1>
1010
</body>
1111

1212
<script src="index.js"></script>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>JavaScript Tutorials</title>
6+
</head>
7+
8+
<body>
9+
<h1>Coding Challenge 3</h1>
10+
</body>
11+
12+
<script src="index.js"></script>
13+
</html>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
// -----------------------------------------------------------------------------
3+
// Coding Challenge 2
4+
// -----------------------------------------------------------------------------
5+
6+
/*
7+
John and his family went on a holiday and went to 3 different restaurants.
8+
The bills were 124,ドル 48ドル and 268ドル.
9+
10+
To tip the waiter a fair amount, John created a simple tip calculator (as a function).
11+
He likes to tip 20% of the bill when the bill is less than 50,ドル 15% when the bill is
12+
between 50ドル and 200,ドル and 10% if the bill is more than 200ドル.
13+
14+
In the end, John would like to have 2 arrays:
15+
1) Containing all three tips (one for each bill)
16+
2) Containing all three final paid amounts (bill + tip).
17+
18+
(NOTE: To calculate 20% of a value, simply multiply it with 20/100 = 0.2)
19+
20+
GOOD LUCK 😀
21+
*/
22+
23+
var bills = [124, 48, 268];
24+
console.log(bills);
25+
26+
var tips = bills.map(function(amount) {
27+
if (amount < 50) {
28+
return (20 / 100) * amount;
29+
} else if (amount >= 50 && amount <= 200) {
30+
return (15 / 100) * amount;
31+
} else {
32+
return (10 / 100) * amount;
33+
}
34+
});
35+
console.log(tips);
36+
37+
var totals = bills.map(function(bill, index) {
38+
return bill + tips[index];
39+
})
40+
console.log(totals);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /