Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
class Avenger {
// Initialization and constructor
isMale: function() {
return this.sex ==M”;
}
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