Created
May 2, 2019 13:07
-
-
Save santhosh77h/8144229f2885a32db36cfb4a0657728b to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/betohiw
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
let Jungle = function(name, energy) { | |
this.name = name; | |
this.energy = energy; | |
}; | |
Jungle.prototype.soundStatus = true; | |
Jungle.prototype.soundEnergy = -3; | |
Jungle.prototype.eatEnergy = 5; | |
Jungle.prototype.sleepEnergy = 10; | |
Jungle.prototype.menu = ["meat", "fish", "bugs", "grain"]; | |
Jungle.prototype.eat = function(ordered) { | |
let result = this.energy + this.eatEnergy; | |
let foodFoundInMenu = this.menu.findIndex(el => el == ordered); | |
if (foodFoundInMenu == -1) { | |
console.log(`${this.name} ordered ${ordered} which is not available in menu`); | |
return; | |
} | |
if (result >= 0) { | |
this.energy = result; | |
return; | |
} | |
console.log(`${this.name} in sifficient energy for Eatting`); | |
}; | |
Jungle.prototype.sleep = function() { | |
let result = this.energy + this.sleepEnergy; | |
if (result >= 0) { | |
this.energy = result; | |
return; | |
} | |
console.log(`${this.name} in sifficient energy for Sleeping`); | |
}; | |
Jungle.prototype.sound = function() { | |
if (!this.soundStatus) { | |
console.log("Jungle has turned off the music system"); | |
return; | |
} | |
let result = this.energy + this.soundEnergy; | |
if (result >= 0) { | |
this.energy = result; | |
return; | |
} | |
console.log(`${this.name} in sifficient energy for making Sound`); | |
}; | |
let Monkey = function(name) { | |
Jungle.call(this, name, 0); | |
this.add = function() { | |
Monkey.count++; | |
}; | |
this.add(); | |
}; | |
let Tiger = function(name) { | |
Jungle.call(this, name, 0); | |
this.add = function() { | |
Tiger.count++; | |
}; | |
this.add(); | |
}; | |
let Snakes = function(name) { | |
Jungle.call(this, name, 0); | |
this.add = function() { | |
Snakes.count++; | |
}; | |
this.add(); | |
}; | |
Snakes.count = 0; | |
Snakes.prototype = Object.create(Jungle.prototype); | |
Tiger.count = 0; | |
Tiger.prototype = Object.create(Jungle.prototype); | |
Tiger.prototype.sleepEnergy = 5; | |
Tiger.prototype.menu = ["meat", "fish", "bugs"]; | |
Monkey.count = 0; | |
Monkey.prototype = Object.create(Jungle.prototype); | |
Monkey.prototype.eatEnergy = 2; | |
Monkey.prototype.soundEnergy = -4; | |
Monkey.prototype.play = function() { | |
if (this.energy >= 8) { | |
this.energy -= 8; | |
console.log("Oooo Oooo Oooo"); | |
return; | |
} | |
console.log("Monkey is too tired."); | |
}; | |
/** | |
* verifying the logic | |
*/ | |
let monkey1 = new Monkey("monkey1"); | |
monkey1.eat("meat"); | |
monkey1.eat("grain"); | |
monkey1.sound(); | |
monkey1.sleep(); | |
monkey1.play(); | |
let tiger1 = new Tiger("tiger1"); | |
tiger1.eat("meat"); | |
tiger1.eat("meat"); | |
tiger1.sound(); | |
tiger1.sleep(); | |
let snake1 = new Snakes("snake1"); | |
snake1.eat("meat"); | |
snake1.eat("grain"); | |
snake1.sound(); | |
snake1.sleep(); | |
console.log( | |
`snake1.energy=${snake1.energy} , mokey1.energy=${ | |
monkey1.energy | |
} , tiger1.energy=${tiger1.energy}` | |
); | |
snake1.eat("meat"); | |
tiger1.eat("grain"); | |
monkey1.eat("grain"); | |
console.log( | |
`snake1.energy=${snake1.energy} , mokey1.energy=${ | |
monkey1.energy | |
} , tiger1.energy=${tiger1.energy}` | |
); | |
snake1.sound(); | |
tiger1.sound(); | |
Jungle.prototype.soundStatus = false; | |
monkey1.sound(); | |
console.log( | |
`snake1.energy=${snake1.energy} , mokey1.energy=${ | |
monkey1.energy | |
} , tiger1.energy=${tiger1.energy}` | |
); | |
monkey1.play(); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript"> | |
let Jungle = function(name, energy) { | |
this.name = name; | |
this.energy = energy; | |
}; | |
Jungle.prototype.soundStatus = true; | |
Jungle.prototype.soundEnergy = -3; | |
Jungle.prototype.eatEnergy = 5; | |
Jungle.prototype.sleepEnergy = 10; | |
Jungle.prototype.menu = ["meat", "fish", "bugs", "grain"]; | |
Jungle.prototype.eat = function(ordered) { | |
let result = this.energy + this.eatEnergy; | |
let foodFoundInMenu = this.menu.findIndex(el => el == ordered); | |
if (foodFoundInMenu == -1) { | |
console.log(`${this.name} ordered ${ordered} which is not available in menu`); | |
return; | |
} | |
if (result >= 0) { | |
this.energy = result; | |
return; | |
} | |
console.log(`${this.name} in sifficient energy for Eatting`); | |
}; | |
Jungle.prototype.sleep = function() { | |
let result = this.energy + this.sleepEnergy; | |
if (result >= 0) { | |
this.energy = result; | |
return; | |
} | |
console.log(`${this.name} in sifficient energy for Sleeping`); | |
}; | |
Jungle.prototype.sound = function() { | |
if (!this.soundStatus) { | |
console.log("Jungle has turned off the music system"); | |
return; | |
} | |
let result = this.energy + this.soundEnergy; | |
if (result >= 0) { | |
this.energy = result; | |
return; | |
} | |
console.log(`${this.name} in sifficient energy for making Sound`); | |
}; | |
let Monkey = function(name) { | |
Jungle.call(this, name, 0); | |
this.add = function() { | |
Monkey.count++; | |
}; | |
this.add(); | |
}; | |
let Tiger = function(name) { | |
Jungle.call(this, name, 0); | |
this.add = function() { | |
Tiger.count++; | |
}; | |
this.add(); | |
}; | |
let Snakes = function(name) { | |
Jungle.call(this, name, 0); | |
this.add = function() { | |
Snakes.count++; | |
}; | |
this.add(); | |
}; | |
Snakes.count = 0; | |
Snakes.prototype = Object.create(Jungle.prototype); | |
Tiger.count = 0; | |
Tiger.prototype = Object.create(Jungle.prototype); | |
Tiger.prototype.sleepEnergy = 5; | |
Tiger.prototype.menu = ["meat", "fish", "bugs"]; | |
Monkey.count = 0; | |
Monkey.prototype = Object.create(Jungle.prototype); | |
Monkey.prototype.eatEnergy = 2; | |
Monkey.prototype.soundEnergy = -4; | |
Monkey.prototype.play = function() { | |
if (this.energy >= 8) { | |
this.energy -= 8; | |
console.log("Oooo Oooo Oooo"); | |
return; | |
} | |
console.log("Monkey is too tired."); | |
}; | |
/** | |
* verifying the logic | |
*/ | |
let monkey1 = new Monkey("monkey1"); | |
monkey1.eat("meat"); | |
monkey1.eat("grain"); | |
monkey1.sound(); | |
monkey1.sleep(); | |
monkey1.play(); | |
let tiger1 = new Tiger("tiger1"); | |
tiger1.eat("meat"); | |
tiger1.eat("meat"); | |
tiger1.sound(); | |
tiger1.sleep(); | |
let snake1 = new Snakes("snake1"); | |
snake1.eat("meat"); | |
snake1.eat("grain"); | |
snake1.sound(); | |
snake1.sleep(); | |
console.log( | |
`snake1.energy=${snake1.energy} , mokey1.energy=${ | |
monkey1.energy | |
} , tiger1.energy=${tiger1.energy}` | |
); | |
snake1.eat("meat"); | |
tiger1.eat("grain"); | |
monkey1.eat("grain"); | |
console.log( | |
`snake1.energy=${snake1.energy} , mokey1.energy=${ | |
monkey1.energy | |
} , tiger1.energy=${tiger1.energy}` | |
); | |
snake1.sound(); | |
tiger1.sound(); | |
Jungle.prototype.soundStatus = false; | |
monkey1.sound(); | |
console.log( | |
`snake1.energy=${snake1.energy} , mokey1.energy=${ | |
monkey1.energy | |
} , tiger1.energy=${tiger1.energy}` | |
); | |
monkey1.play(); | |
</script></body> | |
</html> |
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
let Jungle = function(name, energy) { | |
this.name = name; | |
this.energy = energy; | |
}; | |
Jungle.prototype.soundStatus = true; | |
Jungle.prototype.soundEnergy = -3; | |
Jungle.prototype.eatEnergy = 5; | |
Jungle.prototype.sleepEnergy = 10; | |
Jungle.prototype.menu = ["meat", "fish", "bugs", "grain"]; | |
Jungle.prototype.eat = function(ordered) { | |
let result = this.energy + this.eatEnergy; | |
let foodFoundInMenu = this.menu.findIndex(el => el == ordered); | |
if (foodFoundInMenu == -1) { | |
console.log(`${this.name} ordered ${ordered} which is not available in menu`); | |
return; | |
} | |
if (result >= 0) { | |
this.energy = result; | |
return; | |
} | |
console.log(`${this.name} in sifficient energy for Eatting`); | |
}; | |
Jungle.prototype.sleep = function() { | |
let result = this.energy + this.sleepEnergy; | |
if (result >= 0) { | |
this.energy = result; | |
return; | |
} | |
console.log(`${this.name} in sifficient energy for Sleeping`); | |
}; | |
Jungle.prototype.sound = function() { | |
if (!this.soundStatus) { | |
console.log("Jungle has turned off the music system"); | |
return; | |
} | |
let result = this.energy + this.soundEnergy; | |
if (result >= 0) { | |
this.energy = result; | |
return; | |
} | |
console.log(`${this.name} in sifficient energy for making Sound`); | |
}; | |
let Monkey = function(name) { | |
Jungle.call(this, name, 0); | |
this.add = function() { | |
Monkey.count++; | |
}; | |
this.add(); | |
}; | |
let Tiger = function(name) { | |
Jungle.call(this, name, 0); | |
this.add = function() { | |
Tiger.count++; | |
}; | |
this.add(); | |
}; | |
let Snakes = function(name) { | |
Jungle.call(this, name, 0); | |
this.add = function() { | |
Snakes.count++; | |
}; | |
this.add(); | |
}; | |
Snakes.count = 0; | |
Snakes.prototype = Object.create(Jungle.prototype); | |
Tiger.count = 0; | |
Tiger.prototype = Object.create(Jungle.prototype); | |
Tiger.prototype.sleepEnergy = 5; | |
Tiger.prototype.menu = ["meat", "fish", "bugs"]; | |
Monkey.count = 0; | |
Monkey.prototype = Object.create(Jungle.prototype); | |
Monkey.prototype.eatEnergy = 2; | |
Monkey.prototype.soundEnergy = -4; | |
Monkey.prototype.play = function() { | |
if (this.energy >= 8) { | |
this.energy -= 8; | |
console.log("Oooo Oooo Oooo"); | |
return; | |
} | |
console.log("Monkey is too tired."); | |
}; | |
/** | |
* verifying the logic | |
*/ | |
let monkey1 = new Monkey("monkey1"); | |
monkey1.eat("meat"); | |
monkey1.eat("grain"); | |
monkey1.sound(); | |
monkey1.sleep(); | |
monkey1.play(); | |
let tiger1 = new Tiger("tiger1"); | |
tiger1.eat("meat"); | |
tiger1.eat("meat"); | |
tiger1.sound(); | |
tiger1.sleep(); | |
let snake1 = new Snakes("snake1"); | |
snake1.eat("meat"); | |
snake1.eat("grain"); | |
snake1.sound(); | |
snake1.sleep(); | |
console.log( | |
`snake1.energy=${snake1.energy} , mokey1.energy=${ | |
monkey1.energy | |
} , tiger1.energy=${tiger1.energy}` | |
); | |
snake1.eat("meat"); | |
tiger1.eat("grain"); | |
monkey1.eat("grain"); | |
console.log( | |
`snake1.energy=${snake1.energy} , mokey1.energy=${ | |
monkey1.energy | |
} , tiger1.energy=${tiger1.energy}` | |
); | |
snake1.sound(); | |
tiger1.sound(); | |
Jungle.prototype.soundStatus = false; | |
monkey1.sound(); | |
console.log( | |
`snake1.energy=${snake1.energy} , mokey1.energy=${ | |
monkey1.energy | |
} , tiger1.energy=${tiger1.energy}` | |
); | |
monkey1.play(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment