This repository was archived by the owner on Jan 3, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathexercise-5.js
More file actions
56 lines (45 loc) · 1.86 KB
/
exercise-5.js
File metadata and controls
56 lines (45 loc) · 1.86 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
A coffee machine is defined below.
One can buy three different coffees.
Complete the methods "insertMoney" and "getCoffee" to match the expected result.
insertMoney takes an amount in parameter to add money in the coffee machine.
getCoffee takes a coffee type in parameter and dispends the selected coffee
only if the inserted amount is greater or equal than the price of the coffee!
*/
let coffeeMachine = {
brand: "Super Coffee",
prices: {
cappuccino: 2.40,
blackCoffee: 1.50,
flatWhite: 3.00
},
insertedAmount: 0,
insertMoney: function (amount) {
return this.insertedAmount = amount
},
getCoffee: function (coffee) {
if(this.insertedAmount >= 2.40 && this.insertedAmount< 3.00){
return 'Please take your cappuccino'
}
else if(this.insertedAmount >= 1.50 && this.insertedAmount < 2.40){
return 'Please take your blackCoffee'
}
else if(this.insertedAmount >= 4.00){
return 'Please take your flatWhite'
}
else if(this.insertedAmount >3.00 && this.insertedAmount < 4.00){
return 'Sorry you don\'t have enough money for a flatWhite'
}
}
};
/*
DO NOT EDIT ANYTHING BELOW THIS LINE
*/
coffeeMachine.insertMoney(2.40);
console.log(`Expected result: 'Please take your cappuccino'. Actual result: ${coffeeMachine.getCoffee('cappuccino')}`);
coffeeMachine.insertMoney(1.50);
console.log(`Expected result: 'Please take your blackCoffee'. Actual result: ${coffeeMachine.getCoffee('blackCoffee')}`);
coffeeMachine.insertMoney(4.00);
console.log(`Expected result: 'Please take your flatWhite'. Actual result: ${coffeeMachine.getCoffee('flatWhite')}`);
coffeeMachine.insertMoney(3.40);
console.log(`Expected result: 'Sorry you don't have enough money for a flatWhite'. Actual result: ${coffeeMachine.getCoffee('flatWhite')}`);