Skip to content

Commit e3a6cbf

Browse files
committed
adding code for chapter 7
1 parent 89fe0b7 commit e3a6cbf

File tree

3 files changed

+110
-0
lines changed

3 files changed

+110
-0
lines changed

chapter7/duck.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<title>Ducks</title>
5+
<meta charset="utf-8">
6+
<script>
7+
function Duck(sound) {
8+
this.sound = sound;
9+
this.quack = function() {
10+
console.log(this.sound);
11+
};
12+
}
13+
var toy = new Duck("quack quack");
14+
toy.quack();
15+
console.log(typeof toy);
16+
console.log(toy instanceof Duck);
17+
</script>
18+
</head>
19+
<body>
20+
</body>
21+
</html>

chapter7/typeof.html

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<title>Testing typeof</title>
5+
<meta charset="utf-8">
6+
<script>
7+
var test1 = "abcdef";
8+
var test2 = 123;
9+
var test3 = true;
10+
var test4 = {};
11+
var test5 = [];
12+
var test6;
13+
var test7 = {"abcdef": 123};
14+
var test8 = ["abcdef", 123];
15+
function test9(){
16+
return "abcdef"
17+
};
18+
var test10 = null;
19+
console.log(typeof test1);
20+
console.log(typeof test2);
21+
console.log(typeof test3);
22+
console.log(typeof test4);
23+
console.log(typeof test5);
24+
console.log(typeof test6);
25+
console.log(typeof test7);
26+
console.log(typeof test8);
27+
console.log(typeof test9);
28+
console.log(typeof test10);
29+
</script>
30+
</head>
31+
<body>
32+
</body>
33+
</html>

chapter7/types.html

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<title>Types</title>
5+
<meta charset="utf-8">
6+
<script>
7+
8+
function lieDetectorTest() {
9+
var lies = 0;
10+
11+
var stolenDiamond = { };
12+
if (stolenDiamond) {
13+
console.log("You stole the diamond");
14+
lies++;
15+
}
16+
17+
var car = {
18+
keysInPocket: null
19+
};
20+
if (car.keysInPocket) {
21+
console.log("Uh oh, guess you stole the car!");
22+
lies++;
23+
}
24+
if (car.emptyGasTank) {
25+
console.log("You drove the car after you stole it!");
26+
lies++;
27+
}
28+
29+
var foundYouAtTheCrimeScene = [ ];
30+
if (foundYouAtTheCrimeScene) {
31+
console.log("A sure sign of guilt");
32+
lies++;
33+
}
34+
if (foundYouAtTheCrimeScene[0]) {
35+
console.log("Caught with a stolen item!");
36+
lies++;
37+
}
38+
39+
var yourName = " ";
40+
if (yourName) {
41+
console.log("Guess you lied about your name");
42+
lies++;
43+
}
44+
return lies;
45+
}
46+
var numberOfLies = lieDetectorTest();
47+
console.log("You told " + numberOfLies + " lies!");
48+
if (numberOfLies >= 3) {
49+
console.log("Guilty as charged");
50+
}
51+
52+
</script>
53+
</head>
54+
<body>
55+
</body>
56+
</html>

0 commit comments

Comments
 (0)