Created
July 24, 2018 17:54
-
-
Save sevperez/72176a8e4ef57bf0beeadb52c0a9df3a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function Robot(name, job) { | |
this.name = name; | |
this.job = job; | |
this.introduce = function() { | |
console.log("Hi! I'm " + this.name + ". My job is " + this.job + "."); | |
}; | |
} | |
function AI(name, job, intelligenceLevel) { | |
Robot.call(this, name, job); | |
this.intelligenceLevel = intelligenceLevel; | |
this.testIntelligence = function(level) { | |
if (this.intelligenceLevel > level) { | |
console.log("My intelligence level is superior to", + level + "!"); | |
} else { | |
console.log("Sorry, my intelligence level isn't that high."); | |
} | |
}; | |
} | |
AI.prototype = Object.create(Robot.prototype); | |
AI.prototype.constructor = AI; | |
var GLaDOS = new AI("GLaDOS", "subject testing", 10); | |
console.log(GLaDOS.constructor); | |
// Logs a representation of the AI function | |
GLaDOS.introduce(); | |
// Logs: "Hi! I'm GLaDOS. My job is subject testing." | |
GLaDOS.testIntelligence(5); | |
// Logs: "My intelligence level is superior to 5!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment