Skip to content

Commit a052b7f

Browse files
committed
completed class chapter exercises
1 parent 4d2974d commit a052b7f

2 files changed

Lines changed: 35 additions & 13 deletions

File tree

classes/chapter-examples/ClassExamples01.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,10 @@ fox.color = 'red';
1818
console.log(fox);
1919
console.log(fox.age, fox.color);
2020

21-
//Try modifying or adding properties below.
21+
//Try modifying or adding properties below.
22+
23+
fox.name = 'newFox';
24+
console.log(fox);
25+
26+
let horse = new Astronaut('Horse', 12, 224);
27+
console.log(horse);
Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,33 @@
1-
// Use terminal commands to see what happens when we call Astronaut but do not pass in 3 arguments.
1+
// // Use terminal commands to see what happens when we call Astronaut but do not pass in 3 arguments.
2+
// // console.log(Astronaut);
3+
// // Astronaut();
24

3-
// Next, set default values for 1 or more of the parameters in constructor.
5+
// // Next, set default values for 1 or more of the parameters in constructor.
46

5-
class Astronaut {
6-
constructor(name, age, mass){
7-
this.name = name;
8-
this.age = age;
9-
this.mass = mass;
10-
}
11-
}
7+
// class Astronaut {
8+
// constructor(name = 'Who?', age, mass = 100){
9+
// this.name = name;
10+
// this.age = age;
11+
// this.mass = mass;
12+
// }
13+
// }
1214

13-
let tortoise = new Astronaut('Speedy', 120);
15+
// let tortoise = new Astronaut('Speedy', 120);
1416

15-
console.log(tortoise.name, tortoise.age, tortoise.mass);
17+
// console.log(tortoise.name, tortoise.age, tortoise.mass);
1618

17-
// What happens if we call Astronaut and pass in MORE than 3 arguments? TRY IT!
19+
// // What happens if we call Astronaut and pass in MORE than 3 arguments? TRY IT!
20+
// console.log(tortoise.name, tortoise.age, tortoise.mass, tortoise.color);
21+
// console.log(Astronaut);
22+
// console.log(tortoise);
23+
class Car {
24+
constructor(make, model, year, color, mpg){
25+
this.make = make;
26+
this.model = model;
27+
this.year = year;
28+
this.color = color;
29+
this.mpg = mpg;
30+
}
31+
}
32+
let myCar = new Car('Chevy', 'Astro', 1985, 'gray', 20);
33+
console.log(typeof myCar.year);

0 commit comments

Comments
 (0)