Last active
September 7, 2018 09:40
-
-
Save alansemenov/d4b101c1b9e2c0b7eda0dccee6ae8faf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Avenger { | |
// Initialization and constructor | |
isMale: function() { | |
return this.sex == “M”; | |
} | |
canFly: function() { | |
return this.canFly; | |
} | |
canChangeColor: function() { | |
return this.skinColor.length > 1; | |
} | |
isWhite: function() { | |
return this.skinColor.includes(“white”); | |
} | |
isBlack: function() { | |
return this.skinColor.includes(“black”); | |
} | |
isAncient: function() { | |
return this.age >= 1000; | |
} | |
isOld: function() { | |
return this.age > 80 && this.age < 1000; | |
} | |
} | |
// In another class... | |
function guessAvenger(avenger) { | |
if (avenger.canChangeColor()) { | |
console.log(“Hulk”); | |
return; | |
} | |
if (!avenger.isMale()) { | |
console.log(“Black Widow”); | |
return; | |
} | |
if (avenger.isAncient()) { | |
console.log(“Thor”); | |
return; | |
} | |
if (avenger.isOld()) { | |
console.log(“Captain America”); | |
return; | |
} | |
if (avenger.isBlack()) { | |
if (avenger.canFly()) { | |
console.log(“Falcon”); | |
} | |
else { | |
console.log(“Nick Fury”); | |
} | |
return; | |
} | |
if (avenger.isWhite()) { | |
console.log(“Iron Man”); | |
return; | |
} | |
console.log(“This is not an Avenger!”); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment