-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
54 lines (31 loc) · 1.27 KB
/
script.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
let newConsole = document.getElementById('prompt');
const log = (log) => {
let allLogs = ``;
allLogs += `<h4> > ${log}</h4>`;
newConsole.innerHTML += allLogs
}
function Car(numberOfWheels) {
this.numberOfWheels = numberOfWheels;
}
const car1 = new Car(4);
log(`Car 1 has ${car1.numberOfWheels} wheels`); // Output: "Car 1 has 4 wheels"
const car2 = new Car(4);
log(`Car 2 has ${car2.numberOfWheels} wheels`); // Output: "Car 2 has 4 wheels"
car1.numberOfWheels = 10;
log(`Car 1 now has ${car1.numberOfWheels} wheels`); // Output: "Car 1 now has 10 wheels"
log(`Car 2 now has ${car2.numberOfWheels} wheels`); // Output: "Car 2 now has 4 wheels"
// Car.prototype.numberOfWheels = numberOfWheels * 10; // This can't be Done
function Truck() { }
Truck.prototype.numberOfWheels = 4;
const truck1 = new Truck();
log(`Truck 1 has ${truck1.numberOfWheels} wheels`);
Truck.prototype.numberOfWheels = 10;
const truck2 = new Truck();
log(`Truck 2 has ${truck2.numberOfWheels} wheels`);
truck1.numberOfWheels = 15;
truck2.numberOfWheels = 30;
Truck.prototype.numberOfWheels = [20, 30];
log(`Truck 1 now has ${truck1.numberOfWheels} wheels`);
log(`Truck 2 now has ${truck2.numberOfWheels} wheels`);
const truck3 = new Truck();
log(`Truck 3 now has ${truck3.numberOfWheels} wheels`);