-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
110 lines (92 loc) · 2.47 KB
/
index.js
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
'use strict';
// Given variables
const dishData = [
{
name: "Italian pasta",
price: 9.55
},
{
name: "Rice with veggies",
price: 8.65
},
{
name: "Chicken with potatoes",
price: 15.55
},
{
name: "Vegetarian Pizza",
price: 6.45
},
];
const tax = 1.20;
// Implement getPrices()
function getPrices(taxBoolean) {
for (let dish of dishData) {
let finalPrice;
if (taxBoolean) {
finalPrice = dish.price * tax;
} else if (!taxBoolean) {
finalPrice = dish.price;
} else {
console.log("You need to pass a boolean to the getPrices call!");
return;
}
console.log(`Dish: '${dish.name}' => Price: $${finalPrice}`);
}
}
// Call getPrices()
// getPrices(true);
// console.log("\n");
// getPrices(false);
// OUTPUTS
/**
Dish: 'Italian pasta' => Price: $11.46
Dish: 'Rice with veggies' => Price: $10.38
Dish: 'Chicken with potatoes' => Price: $18.66
Dish: 'Vegetarian Pizza' => Price: $7.74
Dish: 'Italian pasta' => Price: $9.55
Dish: 'Rice with veggies' => Price: $8.65
Dish: 'Chicken with potatoes' => Price: $15.55
Dish: 'Vegetarian Pizza' => Price: $6.45
*/
// Implement getDiscount()
function getDiscount(taxBoolean, guests) {
getPrices(taxBoolean);
let condition = typeof(guests) === 'number' && guests > 0 && guests < 30;
if (condition) {
let discount = 0;
if (guests < 5) {
discount = 5;
} else if (guests >= 5) {
discount = 10;
}
console.log(`Discount is: $${discount}`);
} else {
console.log("The second argument must be a number between 0 and 30");
}
}
// Call getDiscount()
getDiscount(true, 2);
console.log("\n");
getDiscount(false, 10);
console.log("\n");
getDiscount(true, true);
// OUTPUTS
/**
Dish: 'Italian pasta' => Price: $11.46
Dish: 'Rice with veggies' => Price: $10.38
Dish: 'Chicken with potatoes' => Price: $18.66
Dish: 'Vegetarian Pizza' => Price: $7.74
Discount is: $5
Dish: 'Italian pasta' => Price: $9.55
Dish: 'Rice with veggies' => Price: $8.65
Dish: 'Chicken with potatoes' => Price: $15.55
Dish: 'Vegetarian Pizza' => Price: $6.45
Discount is: $10
Dish: 'Italian pasta' => Price: $11.46
Dish: 'Rice with veggies' => Price: $10.38
Dish: 'Chicken with potatoes' => Price: $18.66
Dish: 'Vegetarian Pizza' => Price: $7.74
The second argument must be a number between 0 and 30
*/
// module.exports = index;