Skip to content

Commit 0531831

Browse files
committed
adding chapter 11 files
1 parent 8871791 commit 0531831

23 files changed

+436
-0
lines changed

chapter11/bakeSolution.html

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Anonymous Functions: Bake the cookies</title>
6+
<script>
7+
8+
window.onload = function() {
9+
var button = document.getElementById("bake");
10+
button.onclick = function() {
11+
console.log("Time to bake the cookies.");
12+
cookies.bake(2500);
13+
};
14+
};
15+
16+
var cookies = {
17+
instructions: "Preheat oven to 350...",
18+
bake: function(time) {
19+
console.log("Baking the cookies.");
20+
setTimeout(done, time);
21+
}
22+
};
23+
24+
function done() {
25+
alert("Cookies are ready, take them out to cool.");
26+
console.log("Cooling the cookies.");
27+
var cool = function() {
28+
alert("Cookies are cool, time to eat!");
29+
};
30+
setTimeout(cool, 1000);
31+
};
32+
33+
</script>
34+
</head>
35+
<body>
36+
<form>
37+
<input type="button" id="bake" value="Bake Cookies!">
38+
</form>
39+
</body>
40+
</html>
41+

chapter11/challenge.html

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Extreme JavaScript Challenge</title>
6+
<script>
7+
//
8+
// Use the comments to test each Specimen separately.
9+
//
10+
11+
//
12+
// Specimen #1
13+
//
14+
/*
15+
var secret = "007";
16+
17+
function getSecret() {
18+
var secret = "008";
19+
20+
function getValue() {
21+
return secret;
22+
}
23+
24+
return getValue();
25+
}
26+
27+
var result = getSecret();
28+
console.log(result);
29+
*/
30+
31+
//
32+
// Specimen #2
33+
//
34+
var secret = "007";
35+
36+
function getSecret() {
37+
var secret = "008";
38+
39+
function getValue() {
40+
return secret;
41+
}
42+
43+
return getValue;
44+
}
45+
46+
var getValueFun = getSecret();
47+
var result = getValueFun();
48+
console.log(result);
49+
50+
</script>
51+
</head>
52+
<body> </body>
53+
</html>
54+
137 KB
Loading
20.8 KB
Loading
116 KB
Loading
22.3 KB
Loading
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title> Image Guess </title>
6+
<style>
7+
body { margin: 20px; }
8+
img { margin: 20px; }
9+
</style>
10+
<script>
11+
12+
window.onload = function() {
13+
var images = document.getElementsByTagName("img");
14+
for (var i = 0; i < images.length; i++) {
15+
images[i].onclick = showAnswer;
16+
}
17+
};
18+
19+
function showAnswer(eventObj) {
20+
var image = eventObj.target;
21+
var name = image.id;
22+
name = name + ".jpg";
23+
image.src = name;
24+
25+
setTimeout(function() {
26+
var name = image.id;
27+
name = name + "blur.jpg";
28+
image.src = name;
29+
}, 2000);
30+
}
31+
32+
</script>
33+
</head>
34+
<body>
35+
<img id="zero" src="zeroblur.jpg">
36+
<img id="one" src="oneblur.jpg">
37+
<img id="two" src="twoblur.jpg">
38+
<img id="three" src="threeblur.jpg">
39+
<img id="four" src="fourblur.jpg">
40+
<img id="five" src="fiveblur.jpg">
41+
</body>
42+
</html>
84.6 KB
Loading
32.4 KB
Loading
219 KB
Loading

0 commit comments

Comments
 (0)