Skip to content

Commit 4eed546

Browse files
committed
fixed bug
1 parent dfb66e3 commit 4eed546

File tree

1 file changed

+44
-18
lines changed

1 file changed

+44
-18
lines changed

chapter3/thingamajig.html

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,57 @@
88
</body>
99
<script>
1010
function clunk(times) {
11-
var num = times;
12-
while (num > 0) {
13-
console.log("clunk");
14-
clunkCounter = clunkCounter + 1;
15-
num = num - 1;
16-
}
11+
var num = times;
12+
while (num > 0) {
13+
display("clunk");
14+
num = num - 1;
15+
}
1716
}
1817

1918
function thingamajig(size) {
20-
var facky = 1;
21-
if (size == 0) {
22-
console.log("clank");
23-
} else if (size == 1) {
24-
console.log("thunk");
25-
} else {
26-
while (size > 1) {
27-
facky = facky * size;
28-
size = size - 1;
29-
}
30-
clunk(facky);
31-
}
19+
var facky = 1;
20+
clunkCounter = 0;
21+
if (size == 0) {
22+
display("clank");
23+
} else if (size == 1) {
24+
display("thunk");
25+
} else {
26+
while (size > 1) {
27+
facky = facky * size;
28+
size = size - 1;
29+
}
30+
clunk(facky);
31+
}
32+
}
33+
34+
function display(output) {
35+
console.log(output);
36+
clunkCounter = clunkCounter + 1;
3237
}
3338
var clunkCounter = 0;
39+
thingamajig(0);
40+
console.log(clunkCounter);
41+
42+
clunkCounter = 0;
43+
thingamajig(1);
44+
console.log(clunkCounter);
45+
46+
clunkCounter = 0;
47+
thingamajig(2);
48+
console.log(clunkCounter);
49+
50+
clunkCounter = 0;
51+
thingamajig(3);
52+
console.log(clunkCounter);
53+
54+
clunkCounter = 0;
55+
thingamajig(4);
56+
console.log(clunkCounter);
57+
58+
clunkCounter = 0;
3459
thingamajig(5);
3560
console.log(clunkCounter);
61+
3662
</script>
3763
</body>
3864
</html>

0 commit comments

Comments
 (0)