1class Person {
2 constructor(name) {
3 this.name = name;
4 }
5 introduce() {
6 console.log(`Hello, my name is ${this.name}`);
7 }
8}
1function Person(first, last, age, eye) {
2 this.firstName = first;
3 this.lastName = last;
4 this.age = age;
5 this.eyeColor = eye;
6}
1function Car(make, model, year) {
2 this.make = make;
3 this.model = model;
4 this.year = year;
5}
6
7var car1 = new Car('Eagle', 'Talon TSi', 1993);
8
9console.log(car1.make);
10// expected output: "Eagle"
1// constructor function
2function Person () {
3 this.name = 'John',
4 this.age = 23
5}
6
7// create an object
8const person = new Person();
1// Let's make a function that will accept parameters for our vehicle
2function Car(maker, model, color, tireSize) {
3// Now we will set the paramaters equal to the different attributes of the car
4 this.maker = maker;
5 this.model = model;
6 this.color = color;
7 this.tireSize = tireSize;
8// Next we'll make a method that will give a dynamic description of our car
9 this.description = function() {
10
11 return "My car is a " + color + " " + maker + " " + model + " with " + tireSize + " inch tires."
12
13 }
14
15}
16// Now let's make a new car. I want the car to have these attributes:
17let car1 = new Car("Kia", "Soul", "white", 15);
18// Now we can print the description of out new vehicle to the console
19console.log(car1.description());
20
21// OUTPUT: My car is a white Kia Soul with 15 inch tires.