|
1 | | -// Create a class called User. |
2 | | -// The constructor of the class should have a parameter called `options`. |
3 | | -// `options` will be an object that will have the properties `email` and `password`. |
4 | | -// Set the `email` and `password` properties on the class. |
5 | | -// Add a method called `comparePasswords`. `comparePasswords` should have a parameter |
6 | | -// for a potential password that will be compared to the `password` property. |
7 | | -// Return true if the potential password matches the `password` property. Otherwise return false. |
8 | | - |
9 | | - |
10 | | -/* eslint-disable no-undef */ // Remove this comment once you write your classes. |
11 | | - |
12 | | - |
13 | | -// Create a class called `Animal` and a class called `Cat`. |
14 | | -// `Cat` should extend the `Animal` class. |
15 | | -// Animal and Cat should both have a parameter called `options` in their constructors. |
16 | | -// Animal should have the property `age` that's set in the constructor and the method |
17 | | -// `growOlder` that returns the age. |
18 | | -// Cat should have the property `name` that is set in the constructor and the method |
19 | | -// `meow` that should return the string `<name> meowed!` where `<name>` is the `name` |
20 | | -// property set on the Cat instance. |
21 | | - |
22 | | - |
23 | | -module.exports = { |
24 | | - User, |
25 | | - Cat |
26 | | -}; |
| 1 | +// Create a class called User. |
| 2 | +// The constructor of the class should have a parameter called `options`. |
| 3 | +// `options` will be an object that will have the properties `email` and `password`. |
| 4 | +// Set the `email` and `password` properties on the class. |
| 5 | +// Add a method called `comparePasswords`. `comparePasswords` should have a parameter |
| 6 | +// for a potential password that will be compared to the `password` property. |
| 7 | +// Return true if the potential password matches the `password` property. Otherwise return false. |
| 8 | +class User { |
| 9 | + constructor(options) { |
| 10 | + this.email = options.email; |
| 11 | + this.password = options.password; |
| 12 | + } |
| 13 | + comparePasswords(password) { |
| 14 | + return this.password === password; |
| 15 | + } |
| 16 | +} |
| 17 | + |
| 18 | +/* eslint-disable no-undef */ // Remove this comment once you write your classes. |
| 19 | + |
| 20 | + |
| 21 | +// Create a class called `Animal` and a class called `Cat`. |
| 22 | +// `Cat` should extend the `Animal` class. |
| 23 | +// Animal and Cat should both have a parameter called `options` in their constructors. |
| 24 | +// Animal should have the property `age` that's set in the constructor and the method |
| 25 | +// `growOlder` that returns the age. |
| 26 | +// Cat should have the property `name` that is set in the constructor and the method |
| 27 | +// `meow` that should return the string `<name> meowed!` where `<name>` is the `name` |
| 28 | +// property set on the Cat instance. |
| 29 | +class Animal { |
| 30 | + constructor(options) { |
| 31 | + this.age = options.age; |
| 32 | + } |
| 33 | + growOlder() { |
| 34 | + this.age += 1; |
| 35 | + return this.age; |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +class Cat extends Animal { |
| 40 | + constructor(options) { |
| 41 | + super(options); |
| 42 | + this.name = options.name; |
| 43 | + } |
| 44 | + meow() { |
| 45 | + return `${this.name} meowed!`; |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +module.exports = { |
| 50 | + User, |
| 51 | + Cat |
| 52 | +}; |
0 commit comments