-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfiat.js
More file actions
51 lines (47 loc) · 761 Bytes
/
fiat.js
File metadata and controls
51 lines (47 loc) · 761 Bytes
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
var fiat =
{
make: "Fiat",
model: "500",
year: 1957,
color: "MediumBlue",
passengers: 2,
convertible: false,
mileage: 88000,
started: false,
fuel: 0,
start: function()
{
this.started = true;
},
stop: function()
{
this.started = false;
},
drive: function()
{
if (this.started)
{
if (this.fuel > 0)
{
alert(this.make + " " + this.model + " goes zoom zoom!");
this.fuel = this.fuel - 1;
} else
{
alert("Uh oh, out of fuel.");
this.stop();
}
}
},
addFuel: function (amount)
{
this.fuel = this.fuel + amount;
}
};
fiat.start();
fiat.drive();
fiat.addFuel(2);
fiat.start();
fiat.drive();
fiat.drive();
fiat.drive();
fiat.stop();