forked from bethrobson/Head-First-JavaScript-Programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcarWithDrive.html
More file actions
49 lines (42 loc) · 710 Bytes
/
carWithDrive.html
File metadata and controls
49 lines (42 loc) · 710 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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Car with drive</title>
<script>
var fiat = {
make: "Fiat",
model: "500",
year: 1957,
color: "Medium Blue",
passengers: 2,
convertible: false,
mileage: 88000,
started: false,
start: function() {
this.started = true;
},
stop: function() {
this.started = false;
},
drive: function() {
//
// if we use started instead of this.started,
// our code doesn't work!
//
if (this.started) {
alert("Zoom zoom!");
} else {
alert("You need to start the engine first.");
}
}
};
fiat.drive();
fiat.start();
fiat.drive();
fiat.stop();
</script>
</head>
<body>
</body>
</html>