-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclasses.js
More file actions
30 lines (26 loc) · 826 Bytes
/
classes.js
File metadata and controls
30 lines (26 loc) · 826 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
class Cat {
constructor(name, age) {
this.name = name;
this.age = age;
}
meow() {
console.log(`${this.name} says meow!`);
}
scratch(numberOfTimes) {
for (let x = 1; x <= numberOfTimes; x++) {
console.log('Scratch');
}
}
// scratch(numberOfTimes) {
// console.log(`${this.name} scratches ${numberOfTimes} times!`);
// }
}
const myFirstCat = new Cat("Fluffy", 5);
console.log(myFirstCat); // Cat { name: 'Fluffy', age: 5 }
console.log(myFirstCat.name); // Fluffy
const mySecondCat = new Cat("Bella", 3);
console.log(mySecondCat); // Cat { name: 'Bella', age: 3 }
console.log(mySecondCat.name); // Bella
myFirstCat.meow(); // Fluffy says meow!
mySecondCat.meow(); // Bella says meow!
myFirstCat.scratch(4); // Fluffy scratches 3 times!