-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtips.js
More file actions
35 lines (30 loc) · 1.32 KB
/
tips.js
File metadata and controls
35 lines (30 loc) · 1.32 KB
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
// Coding Challenge #4
// Steven wants to build a very simple tip calculator for whenever he goes eating in a
// restaurant. In his country, it's usual to tip 15% if the bill value is between 50 and
// 300. If the value is different, the tip is 20%.
// Your tasks:
// 1. Calculate the tip, depending on the bill value. Create a variable called 'tip' for
// this. It's not allowed to use an if/else statement � (If it's easier for you, you can
// start with an if/else statement, and then try to convert it to a ternary
// operator!)
// 2. Print a string to the console containing the bill value, the tip, and the final value
// (bill + tip). Example: “The bill was 275, the tip was 41.25, and the total value
// 316.25”
// Test data:
// § Data 1: Test for bill values 275, 40 and 430
// Hints:
// § To calculate 20% of a value, simply multiply it by 20/100 = 0.2
// § Value X is between 50 and 300, if it's >= 50 && <= 300
const bill = 49;
if (bill >= 50 && bill <= 300) {
const tips = bill * (15 / 100);
const total = bill + tips;
console.log(total);
} else if (bill <= 50) {
const tips = bill * (20 / 100);
const total = bill + tips;
console.log(total);
}
const totals = (bill >= 50 && bill <= 300) ? (bill * (15 / 100)) + bill : (bill * (20 / 100)) + bill;
console.log(totals);
const bills = [125, 555, 44];