Challenge: Solution Review
This lesson will explain the solution to the problem from the last coding challenge.
We'll cover the following...
Solution #
Press + to interact
class SuperHero {constructor(name,power) {this.name = namethis.power = power}}function SuperHeroWithSword(superhero){superhero.sword = truesuperhero.hasSword= function(){return `${this.name}'s power is ${this.power}, and he also has a sword now.`}return superhero;}function SuperHeroWithSuperSpeed(superhero) {superhero.superSpeed = truesuperhero.hasSuperSpeed= function(){return `${this.name}'s power is ${this.power}, and he also has the super speed now.`}return superhero;}function SuperHeroWithSpeedandSword(superhero){superhero.speedAndSword = truesuperhero.hasSpeedAndSword = function(){return `${this.name}'s power is ${this.power}, and he also has both super speed and a sword now.`}return superhero;}var superhero1 = new SuperHero("Fire Man", "Fire")SuperHeroWithSword(superhero1)console.log(superhero1.hasSword())SuperHeroWithSuperSpeed(superhero1)console.log(superhero1.hasSuperSpeed())var superhero2 = new SuperHero("Ice Man", "Ice")SuperHeroWithSpeedandSword(superhero2)console.log(superhero2.hasSpeedAndSword())
Explanation
Let’s start by going ...