-
Notifications
You must be signed in to change notification settings - Fork 618
/
constructors-exercises.js
executable file
·36 lines (30 loc) · 1.18 KB
/
constructors-exercises.js
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
// Create a constructor function for a Person, each person should have a firstName, lastName, favoriteColor and favoriteNumber.
function Person(firstName, lastName, favoriteColor, favoriteNumber){
this.firstName = firstName;
this.lastName = lastName;
this.favoriteColor = favoriteColor;
this.favoriteNumber = favoriteNumber;
}
// Write a method called multiplyFavoriteNumber that takes in a number and returns the product of the number and the Person's favorite number
function Person(firstName, lastName, favoriteColor, favoriteNumber){
this.firstName = firstName;
this.lastName = lastName;
this.favoriteColor = favoriteColor;
this.favoriteNumber = favoriteNumber;
this.multiplyFavoriteNumber = function(num){
return num * this.favoriteNumber;
}
}
// refactor
function Parent(firstName, lastName, favoriteColor, favoriteFood){
this.firstName = firstName;
this.lastName = lastName;
this.favoriteColor = favoriteColor;
this.favoriteFood = favoriteFood;
}
function Child(firstName, lastName, favoriteColor, favoriteFood){
this.firstName = firstName;
this.lastName = lastName;
this.favoriteColor = favoriteColor;
this.favoriteFood = favoriteFood;
}