-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconstructors.html
More file actions
36 lines (28 loc) · 1.06 KB
/
constructors.html
File metadata and controls
36 lines (28 loc) · 1.06 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
<html>
<head>
<body>
<script>class Car{
constructor(name,year){
this.name = name;
this.year = year;
}
age(){
let date =new Date();
return date.getFullYear() - this.year;
}
brand(){
return this.name;
}
}
let myCar1 = new Car("Ford", 2014);
console.log("MY CAR " + myCar1.brand() + " IS " + myCar1.age()+" years old");
let myCar2 = new Car("punch", 2021);
console.log("MY CAR " + myCar2.brand() + " IS " + myCar2.age()+" years old");
let myCar3 = new Car("baleno", 2018);
console.log("MY CAR " + myCar3.brand() + " IS " + myCar3.age()+" years old");
let myCar4 = new Car("swift", 2008);
console.log("MY CAR " + myCar4.brand() + " IS " + myCar4.age()+" years old");
</script>
</body>
</head>
</html>