Guest User

Untitled

a guest
Jan 21st, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. // Part 1
  2. // Create a class called User using the ES6 class keyword.
  3. // The constructor of the class should have a parameter called `options`.
  4. // `options` will be an object that will have the properties `email` and `password`.
  5. // Set the `email` and `password` properties on the class.
  6. // Add a method called `comparePasswords`. `comparePasswords` should have a parameter
  7. // for a potential password that will be compared to the `password` property.
  8. // Return true if the potential password matches the `password` property. Otherwise return false.
  9. class User {
  10. constructor(options) {
  11. this.email = options.email;
  12. this.password = options.password;
  13. }
  14. comparePasswords(password) {
  15. return (this.password === password);
  16. }
  17. }
  18.  
  19. // Part 2
  20. // Create a class called `Animal` and a class called `Cat` using ES6 classes.
  21. // `Cat` should extend the `Animal` class.
  22. // Animal and Cat should both have a parameter called `options` in their constructors.
  23. // Animal should have the property `age` that's set in the constructor and the method
  24. // `growOlder` that returns the age after incrementing it.
  25. // Cat should have the property `name` that is set in the constructor and the method
  26. // `meow` that should return the string `<name> meowed!` where `<name>` is the `name`
  27. // property set on the Cat instance.
  28.  
  29. class Animal {
  30. constructor(options) {
  31. this.age = options.age;
  32. }
  33. growOlder() {
  34. return ++this.age;
  35. }
  36. }
  37.  
  38. class Cat extends Animal {
  39. constructor(options) {
  40. super(options);
  41. this.name = options.name;
  42. }
  43. meow() {
  44. return `${this.name} meowed! where ${this.name} is the name`;
  45. }
  46. }
Add Comment
Please, Sign In to add comment