forked from LaunchCodeEducation/javascript-projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClassExamples01.js
More file actions
37 lines (29 loc) · 743 Bytes
/
Copy pathClassExamples01.js
File metadata and controls
37 lines (29 loc) · 743 Bytes
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
//Try adding new properties inside constructor.
class Astronaut {
constructor(name, age, mass){
this.name = name;
this.age = age;
this.mass = mass;
}
}
let fox = new Astronaut('Fox', 7, 12);
console.log(fox);
console.log(typeof fox.age, fox.color);
fox.age = 9;
fox.color = 'red';
console.log(fox);
console.log(fox.age, fox.color);
//Try modifying or adding properties below.
class Car {
constructor(make, model, year, color, mpg){
this.make = make;
this.model = model;
this.year = year;
this.color = color;
this.mpg = mpg;
}
}
// let myCar = new Car('Chevy', 'Astro', 1985, 'gray', 20)
// console.log(typeof myCar.year)
let myCar = new Car('Tesla', 'Model S', 2019)
console.log(myCar)