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 path2-water-bottle.js
More file actions
50 lines (42 loc) · 1.2 KB
/
2-water-bottle.js
File metadata and controls
50 lines (42 loc) · 1.2 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
/*
Create an object that acts like a water bottle.
It will need a volume key to store how full or empty the bottle is.
It will be 100 when full and 0 when empty.
Give your water bottle methods for filling it up,
drinking some of it, and emptying it.
We made a start on this for you here:
*/
let bottle = {
volume: 0,
fill: function() {
calling this function should make you bottles volume = 100;
this.volume = 100;
return this.volume;
},
drink: function() {
calling this function should decrease your bottles volume by 10;
this.volume -= 10;
return this.volume;
},
empty: function() {
// this function should return true if your bottles volume = 0
if(this.volume === 0){
return true;
}
}
};
/*
--TIP--
Remember that for changing properties on the current object inside one of its
methods you can refer to it by its variable name: `bottle`.
Once you have completed your object run the following and see if your answer
matches the expected result at the bottom :)
*/
bottle.fill();
bottle.drink();
bottle.drink();
bottle.drink();
if (!bottle.empty()) {
console.log(`bottles volume = ${bottle.volume}`);
}
console.log("Above volume should be: 70");