Skip to content

Instantly share code, notes, and snippets.

@sevperez
Created July 24, 2018 17:54
Show Gist options
  • Save sevperez/72176a8e4ef57bf0beeadb52c0a9df3a to your computer and use it in GitHub Desktop.
Save sevperez/72176a8e4ef57bf0beeadb52c0a9df3a to your computer and use it in GitHub Desktop.
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