forked from bethrobson/Head-First-JavaScript-Programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcarAndDog.html
More file actions
132 lines (113 loc) · 3.16 KB
/
carAndDog.html
File metadata and controls
132 lines (113 loc) · 3.16 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Car Constructor</title>
<script>
function Car(params) {
this.make = params.make;
this.model = params.model;
this.year = params.year;
this.color = params.color;
this.passengers = params.passengers;
this.convertible = params.convertible;
this.mileage = params.mileage;
this.started = false;
this.start = function() {
this.started = true;
};
this.stop = function() {
this.started = false;
};
this.drive = function() {
if (this.started) {
console.log(this.make + " " + this.model + " goes zoom zoom!");
} else {
console.log("Start the engine first.");
}
};
}
var cadiParams = {make: "GM",
model: "Cadillac",
year: 1955,
color: "tan",
passengers: 5,
convertible: false,
miles: 12892};
var cadi = new Car(cadiParams);
var chevyParams = {make: "Chevy",
model: "Bel Air",
year: 1957,
color: "red",
passengers: 2,
convertible: false,
miles: 1021};
var chevy = new Car(chevyParams);
var taxiParams= {make: "Webville Motors",
model: "Taxi",
year: 1955,
color: "yellow",
passengers: 4,
convertible: false,
miles: 281341};
var taxi = new Car(taxiParams);
var fiatParams= {make: "Webville Motors",
model: "500",
year: 1957,
color: "Medium Blue",
passengers: 2,
convertible: false,
miles: 88000};
var fiat = new Car("Fiat", "500", 1957, "Medium Blue", 2, false, 88000);
var testParams= {make: "Webville Motors",
model: "Test Car",
year: 2014,
color: "marine",
passengers: 2,
convertible: true,
miles: 21};
var testCar = new Car("WebVille Motors", "Test Car", 2014, "marine", 2, true, 21);
var cars = [chevy, cadi, taxi, fiat, testCar];
/*
* Commented out so we don't have to see all the alerts again!
*
for(var i = 0; i < cars.length; i++) {
cars[i].start();
cars[i].drive();
cars[i].drive();
cars[i].stop();
}
*/
function Dog(name, breed, weight) {
this.name = name;
this.breed = breed;
this.weight = weight;
this.bark = function() {
if (this.weight > 25) {
alert(this.name + " says Woof!");
} else {
alert(this.name + " says Yip!");
}
};
}
var limoParams = {make: "Webville Motors",
model: "limo",
year: 1983,
color: "black",
passengers: 12,
convertible: true,
mileage: 21120};
var limo = new Car(limoParams);
var limoDog = new Dog("Rhapsody In Blue", "Poodle", 40);
console.log(limo.make + " " + limo.model + " is a " + typeof limo);
console.log(limoDog.name + " is a " + typeof limoDog);
</script>
</head>
<body>
</body>
</html>
</script>
</head>
<body>
</body>
</html>