Skip to content

Commit b59ca7f

Browse files
committed
fixes to code in chapter 5
1 parent 4eed546 commit b59ca7f

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

chapter5/carWithDrive.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
},
2525

2626
drive: function() {
27+
//
28+
// if we use started instead of this.started,
29+
// our code doesn't work!
30+
//
2731
if (this.started) {
2832
alert("Zoom zoom!");
2933
} else {

chapter5/eightball.html

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<title>Magic Eightball</title>
5+
<meta charset="utf-8">
6+
<script>
7+
8+
var eightBall = {
9+
index: 0,
10+
advice: ["yes", "no", "maybe", "not a chance"],
11+
shake: function() {
12+
this.index = this.index + 1;
13+
if (this.index >= this.advice.length) {
14+
this.index = 0;
15+
}
16+
},
17+
look: function() {
18+
return this.advice[this.index];
19+
}
20+
};
21+
22+
eightBall.shake();
23+
console.log(eightBall.look());
24+
25+
eightBall.shake();
26+
console.log(eightBall.look());
27+
28+
eightBall.shake();
29+
console.log(eightBall.look());
30+
31+
</script>
32+
</head>
33+
<body>
34+
</body>
35+
</html>
36+

0 commit comments

Comments
 (0)