How do I simplify my virtual zoo game through Object Oriented Programming? [closed]Object Oriented JavaScript...
How to implement a feedback to keep the DC gain at zero for this conceptual passive filter?
Are the IPv6 address space and IPv4 address space completely disjoint?
What changes for testers when they are testing in agile environments?
What does routing an IP address mean?
Non-trope happy ending?
If magnesium reacts with oxygen to produce magnesium oxide only on the application of heat, then why isn't it categorised as an endothermic reaction?
Why did the EU agree to delay the Brexit deadline?
Is this toilet slogan correct usage of the English language?
Aragorn's "guise" in the Orthanc Stone
What is going wrong in this circuit which supposedly should step down AC to arduino friendly voltage?
How to write values with uncertainty and units with brackets: (339+-14) m/s
copy and scale one figure (wheel)
Freedom of speech and where it applies
Creating nested elements dynamically
Open a doc from terminal, but not by its name
Is it improper etiquette to ask your opponent what his/her rating is before the game?
Are Captain Marvel's powers affected by Thanos' actions in Infinity War
Python scanner for the first free port in a range
What should you do when eye contact makes your subordinate uncomfortable?
Why can Carol Danvers change her suit colours in the first place?
When were female captains banned from Starfleet?
What is the evidence for the "tyranny of the majority problem" in a direct democracy context?
What percentage of fillings performed today are done with mercury amalgam?
How can I block email signup overlays or javascript popups in Safari?
How do I simplify my virtual zoo game through Object Oriented Programming? [closed]
Object Oriented JavaScript optimizationHow object oriented is my Crazy Eights game?Object-oriented rock-paper-scissors gameSimple object-oriented calculatorObject-oriented dungeon crawler gameObject-oriented fractal treeObject-Oriented Sorting AlgorithmsObject-oriented Bank classObject-oriented PDO wrapperObject-oriented student library
$begingroup$
I have finished my code for a "Virtual Zoo" game and I'm wondering how I would make the animals I added so far (Lion, Tiger, Bear) into sub classes so it's easier for me to add an animal in the future and the code would look neater.
My goal if possible would also be to add the attributes of 'health' and 'tiredness' to each animal through OOP.
Could someone show me how to make a parent class: animal with the attributes of tiredness and health while the subclasses lion, tiger, and bear can be subclasses?
<html>
<head>
<title>Virtual Pet</title>
<script>
// Virtual Pet Stats and starting values
// TODO: Change the name of your Virtual Pet on the line below.
var petName = "Virtual Pet";
var petStatus = "healthy";
var budget = 100000;
var profit = 0;
var totalLions = 0;
var totalTigers = 0;
var totalBears = 0;
var lionHealth = 60;
var maxLionHealth = 100;
var tigerHealth = 60;
var maxTigerHealth = 100;
var bearHealth = 60;
var maxBearHealth = 100;
var lionTiredness = 70;
var maxLionTiredness = 0;
var tigerTiredness = 70;
var maxTigerTiredness = 0;
var bearTiredness = 70;
var maxBearTiredness = 0;
/*var tiger = new animal("Tiger",0.5);
var lion = new animal("Lion",0.5);
var bear = new animal("Bear",1);
// TODO: Add more Virtual Pet stats that will be modified by your functions
function animal(name, profit) {
this.name = name;
this.profit = profit;
this.greeting = function() {
alert("You just bought a" + this.name + "He currently makes " + this.profit + "per second.");
};
};
*/
// Increases the current health of the Virtual Pet until it is maxed out.
function lion() {
if (budget >= 20000) {
budget -= 20000;
profit += 2.5;
totalLions += 1;
alert ("You just purchased a Lion, your profit has increased to " + profit + "$. You now own " + totalLions + " Lions.");
} else {
var difference = 20000 - budget;
alert ("You need " + difference + " more dollars to purchase a Lion.");
}
}
function tiger() {
if (budget >= 10000) {
budget -= 10000;
profit += 2.5;
totalTigers += 1;
alert ("You just purchased a Tiger, your profit has increased to " + profit + "$. You now own " + totalTigers + " Tigers.");
} else {
var difference = 10000 - budget;
alert ("You need " + difference + " more dollars to purchase a Tiger.");
}
}
function bear() {
if (budget >= 20000) {
budget -= 20000;
profit += 5;
totalBears += 1;
alert ("You just purchased a Bear, your profit has increased to " + profit + "$. You now own " + totalBears + " Bears.");
} else {
var difference = 20000 - budget;
alert ("You need " + difference + " more dollars to purchase a Bear.");
}
}
/*function exercise()
{
currentHealth = currentHealth + 5;
if(currentHealth > maxHealth)
{
currentHealth = maxHealth;
}
// Update the display after an action has occurred.
updateDisplay();
}
*/
function exercise() {
lionHealth = lionHealth + 6;
tigerHealth = tigerHealth + 4;
bearHealth = bearHealth + 4;
if (lionHealth > maxLionHealth)
{
lionHealth = maxLionHealth;
} if (tigerHealth > maxTigerHealth) {
tigerHealth = maxTigerHealth;
} if (bearHealth > maxBearHealth) {
bearHealth = maxBearHealth;
}
updateDisplay();
}
function sleep(){
lionTiredness = lionTiredness - 10;
tigerTiredness = tigerTiredness - 20;
bearTiredness = bearTiredness - 20;
if (lionTiredness < maxLionTiredness)
{
lionTiredness = maxLionTiredness;
} if (tigerTiredness < maxTigerTiredness) {
tigerTiredness = maxTigerTiredness;
} if (bearTiredness < maxBearTiredness) {
bearTiredness = maxBearTiredness;
}
updateDisplay();
}
// TODO: Write new functions that will process and modify the new stats you have created. (The majority of your new code should go here.)
// Modifies any stats that automatically change every few seconds.
// (For example, health decreases every few seconds so the play needs to occationally exercise their Virtual Pet)
function changesOverTime()
{
lionHealth = lionHealth - 7.5;
tigerHealth = tigerHealth - 5;
bearHealth = bearHealth - 5;
lionTiredness = lionTiredness + 25;
tigerTiredness = tigerTiredness + 5;
bearTiredness = bearTiredness + 5;
if (lionTiredness > 100)
{
lionTiredness = 100;
} if (tigerTiredness > 100) {
tigerTiredness = 100;
} if (bearTiredness > 100) {
bearTiredness = 100;
}
budget = budget + profit;
// TODO: Add in other changes to the Virtual Pet stats that occur on a regular basis.
}
// Checks the pet's health and modifies the status accordingly
function checkHealth()
{
if(lionHealth <= 0 || tigerHealth <= 0 || bearHealth <= 0)
{
petStatus = "Dead";
currentHealth = 0;
}
//TODO (Optional): Add other health status checks (For example, sick if health < 15)
}
// Displays a Title to the screen for your Virtual Pet game
function displayTitle()
{
// TODO (Optional): Create your own title
}
// Displays the current pet stats to the screen.
function displayPetStats()
{
document.write("<h2>" + petName + " Status: " + petStatus + "</h2>");
<!-- document.write("<p>Health = " + currentHealth + " Max Health = " + maxHealth + "</p>"); -->
<!-- document.write("<p>Tiredness = " + tiredness + " Max Tiredness = " + maxTiredness + "</p>"); -->
document.write("<p>Budget = " + budget);
document.write("<p>Profit per second = " + profit);
if (totalLions >= 1) {
document.write("<p>Total Lions = " + totalLions);
document.write("<p>Lion Health = " + lionHealth);
document.write("<p>Lion Tiredness = " + lionTiredness);
}
if (totalTigers >= 1) {
document.write("<p>Total Tigers = " + totalTigers);
document.write("<p>Tiger Health = " + tigerHealth);
document.write("<p>Tiger Tiredness = " + tigerTiredness);
}
if (totalBears >= 1) {
document.write("<p>Total Bears = " + totalBears);
document.write("<p>Bear Health = " + bearHealth);
document.write("<p>Bear Tiredness = " + bearTiredness);
}
// TODO: Add the display of new Virtual Pet stats here
document.close();
}
// Displays the buttons to the screen enabling the user to interact with their virtual pet.
function displayUserOptions()
{
if(petStatus != "Dead")
{
document.write("<button onclick='exercise()'>Exercise</button>");
document.write("<button onclick='sleep()'>Sleep</button>nnn");
document.write("<button onclick='tiger()'>Tiger</button>");
document.write("<button onclick='lion()'>Lion</button>");
document.write("<button onclick='bear()'>Bear</button>");
// TODO: Create buttons for other actions
}
}
// Calls all the functions that display information to the screen.
function updateDisplay()
{
displayTitle();
displayUserOptions();
displayPetStats();
}
// This function executes the game and manages the passing of time.
function gameLoop(timestamp)
{
document.body.style.backgroundColor = "#f3f3f3";
document.body.style.backgroundImage = "url('https://wallpapercave.com/wp/4W0u3iC.jpg')";
if(timestamp > last_iteration + time_interval)
{
last_iteration = timestamp;
changesOverTime();
checkHealth();
// TODO: Check other Virtual Pet stats and update the petStatus accordingly
// After all stats updates are done, update/recreate the display
updateDisplay();
}
// Life continues unless the Virtual Pet is dead (health <= 0)
if(petStatus != "Dead")
{
// Executes the gameLoop function once again.
requestAnimationFrame(gameLoop);
}
}
// Other global variables that control the timing of the game.
var time_interval = 5000;
var last_iteration = 0;
</script>
</head>
<h1>My Virtual Pet!</h1>
<!-- Initiate the gameLoop for the first time.-->
<button onclick='gameLoop()'>Bring my Virtual Pet to Life!</button>
</body>
</html>
javascript beginner object-oriented
$endgroup$
closed as off-topic by yuri, Gerrit0, Toby Speight, Zeta, Mast Mar 14 at 21:02
This question appears to be off-topic. The users who voted to close gave these specific reasons:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Toby Speight, Zeta, Mast
- "Authorship of code: Since Code Review is a community where programmers improve their skills through peer review, we require that the code be posted by an author or maintainer of the code, that the code be embedded directly, and that the poster know why the code is written the way it is." – yuri, Gerrit0
If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
$begingroup$
I have finished my code for a "Virtual Zoo" game and I'm wondering how I would make the animals I added so far (Lion, Tiger, Bear) into sub classes so it's easier for me to add an animal in the future and the code would look neater.
My goal if possible would also be to add the attributes of 'health' and 'tiredness' to each animal through OOP.
Could someone show me how to make a parent class: animal with the attributes of tiredness and health while the subclasses lion, tiger, and bear can be subclasses?
<html>
<head>
<title>Virtual Pet</title>
<script>
// Virtual Pet Stats and starting values
// TODO: Change the name of your Virtual Pet on the line below.
var petName = "Virtual Pet";
var petStatus = "healthy";
var budget = 100000;
var profit = 0;
var totalLions = 0;
var totalTigers = 0;
var totalBears = 0;
var lionHealth = 60;
var maxLionHealth = 100;
var tigerHealth = 60;
var maxTigerHealth = 100;
var bearHealth = 60;
var maxBearHealth = 100;
var lionTiredness = 70;
var maxLionTiredness = 0;
var tigerTiredness = 70;
var maxTigerTiredness = 0;
var bearTiredness = 70;
var maxBearTiredness = 0;
/*var tiger = new animal("Tiger",0.5);
var lion = new animal("Lion",0.5);
var bear = new animal("Bear",1);
// TODO: Add more Virtual Pet stats that will be modified by your functions
function animal(name, profit) {
this.name = name;
this.profit = profit;
this.greeting = function() {
alert("You just bought a" + this.name + "He currently makes " + this.profit + "per second.");
};
};
*/
// Increases the current health of the Virtual Pet until it is maxed out.
function lion() {
if (budget >= 20000) {
budget -= 20000;
profit += 2.5;
totalLions += 1;
alert ("You just purchased a Lion, your profit has increased to " + profit + "$. You now own " + totalLions + " Lions.");
} else {
var difference = 20000 - budget;
alert ("You need " + difference + " more dollars to purchase a Lion.");
}
}
function tiger() {
if (budget >= 10000) {
budget -= 10000;
profit += 2.5;
totalTigers += 1;
alert ("You just purchased a Tiger, your profit has increased to " + profit + "$. You now own " + totalTigers + " Tigers.");
} else {
var difference = 10000 - budget;
alert ("You need " + difference + " more dollars to purchase a Tiger.");
}
}
function bear() {
if (budget >= 20000) {
budget -= 20000;
profit += 5;
totalBears += 1;
alert ("You just purchased a Bear, your profit has increased to " + profit + "$. You now own " + totalBears + " Bears.");
} else {
var difference = 20000 - budget;
alert ("You need " + difference + " more dollars to purchase a Bear.");
}
}
/*function exercise()
{
currentHealth = currentHealth + 5;
if(currentHealth > maxHealth)
{
currentHealth = maxHealth;
}
// Update the display after an action has occurred.
updateDisplay();
}
*/
function exercise() {
lionHealth = lionHealth + 6;
tigerHealth = tigerHealth + 4;
bearHealth = bearHealth + 4;
if (lionHealth > maxLionHealth)
{
lionHealth = maxLionHealth;
} if (tigerHealth > maxTigerHealth) {
tigerHealth = maxTigerHealth;
} if (bearHealth > maxBearHealth) {
bearHealth = maxBearHealth;
}
updateDisplay();
}
function sleep(){
lionTiredness = lionTiredness - 10;
tigerTiredness = tigerTiredness - 20;
bearTiredness = bearTiredness - 20;
if (lionTiredness < maxLionTiredness)
{
lionTiredness = maxLionTiredness;
} if (tigerTiredness < maxTigerTiredness) {
tigerTiredness = maxTigerTiredness;
} if (bearTiredness < maxBearTiredness) {
bearTiredness = maxBearTiredness;
}
updateDisplay();
}
// TODO: Write new functions that will process and modify the new stats you have created. (The majority of your new code should go here.)
// Modifies any stats that automatically change every few seconds.
// (For example, health decreases every few seconds so the play needs to occationally exercise their Virtual Pet)
function changesOverTime()
{
lionHealth = lionHealth - 7.5;
tigerHealth = tigerHealth - 5;
bearHealth = bearHealth - 5;
lionTiredness = lionTiredness + 25;
tigerTiredness = tigerTiredness + 5;
bearTiredness = bearTiredness + 5;
if (lionTiredness > 100)
{
lionTiredness = 100;
} if (tigerTiredness > 100) {
tigerTiredness = 100;
} if (bearTiredness > 100) {
bearTiredness = 100;
}
budget = budget + profit;
// TODO: Add in other changes to the Virtual Pet stats that occur on a regular basis.
}
// Checks the pet's health and modifies the status accordingly
function checkHealth()
{
if(lionHealth <= 0 || tigerHealth <= 0 || bearHealth <= 0)
{
petStatus = "Dead";
currentHealth = 0;
}
//TODO (Optional): Add other health status checks (For example, sick if health < 15)
}
// Displays a Title to the screen for your Virtual Pet game
function displayTitle()
{
// TODO (Optional): Create your own title
}
// Displays the current pet stats to the screen.
function displayPetStats()
{
document.write("<h2>" + petName + " Status: " + petStatus + "</h2>");
<!-- document.write("<p>Health = " + currentHealth + " Max Health = " + maxHealth + "</p>"); -->
<!-- document.write("<p>Tiredness = " + tiredness + " Max Tiredness = " + maxTiredness + "</p>"); -->
document.write("<p>Budget = " + budget);
document.write("<p>Profit per second = " + profit);
if (totalLions >= 1) {
document.write("<p>Total Lions = " + totalLions);
document.write("<p>Lion Health = " + lionHealth);
document.write("<p>Lion Tiredness = " + lionTiredness);
}
if (totalTigers >= 1) {
document.write("<p>Total Tigers = " + totalTigers);
document.write("<p>Tiger Health = " + tigerHealth);
document.write("<p>Tiger Tiredness = " + tigerTiredness);
}
if (totalBears >= 1) {
document.write("<p>Total Bears = " + totalBears);
document.write("<p>Bear Health = " + bearHealth);
document.write("<p>Bear Tiredness = " + bearTiredness);
}
// TODO: Add the display of new Virtual Pet stats here
document.close();
}
// Displays the buttons to the screen enabling the user to interact with their virtual pet.
function displayUserOptions()
{
if(petStatus != "Dead")
{
document.write("<button onclick='exercise()'>Exercise</button>");
document.write("<button onclick='sleep()'>Sleep</button>nnn");
document.write("<button onclick='tiger()'>Tiger</button>");
document.write("<button onclick='lion()'>Lion</button>");
document.write("<button onclick='bear()'>Bear</button>");
// TODO: Create buttons for other actions
}
}
// Calls all the functions that display information to the screen.
function updateDisplay()
{
displayTitle();
displayUserOptions();
displayPetStats();
}
// This function executes the game and manages the passing of time.
function gameLoop(timestamp)
{
document.body.style.backgroundColor = "#f3f3f3";
document.body.style.backgroundImage = "url('https://wallpapercave.com/wp/4W0u3iC.jpg')";
if(timestamp > last_iteration + time_interval)
{
last_iteration = timestamp;
changesOverTime();
checkHealth();
// TODO: Check other Virtual Pet stats and update the petStatus accordingly
// After all stats updates are done, update/recreate the display
updateDisplay();
}
// Life continues unless the Virtual Pet is dead (health <= 0)
if(petStatus != "Dead")
{
// Executes the gameLoop function once again.
requestAnimationFrame(gameLoop);
}
}
// Other global variables that control the timing of the game.
var time_interval = 5000;
var last_iteration = 0;
</script>
</head>
<h1>My Virtual Pet!</h1>
<!-- Initiate the gameLoop for the first time.-->
<button onclick='gameLoop()'>Bring my Virtual Pet to Life!</button>
</body>
</html>
javascript beginner object-oriented
$endgroup$
closed as off-topic by yuri, Gerrit0, Toby Speight, Zeta, Mast Mar 14 at 21:02
This question appears to be off-topic. The users who voted to close gave these specific reasons:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Toby Speight, Zeta, Mast
- "Authorship of code: Since Code Review is a community where programmers improve their skills through peer review, we require that the code be posted by an author or maintainer of the code, that the code be embedded directly, and that the poster know why the code is written the way it is." – yuri, Gerrit0
If this question can be reworded to fit the rules in the help center, please edit the question.
$begingroup$
It there a reason you are not using es6 classes?
$endgroup$
– Michael Warner
Mar 14 at 13:13
1
$begingroup$
The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to simply state the task accomplished by the code. Please see How to get the best value out of Code Review - Asking Questions for guidance on writing good question titles.
$endgroup$
– BCdotWEB
Mar 14 at 13:20
$begingroup$
@MichaelWarner because I am new to Javascript, im trying to see an example of how to do this with the script I wrote.
$endgroup$
– Jon Frank
Mar 14 at 13:34
2
$begingroup$
This looks like unfinished homework.
$endgroup$
– yuri
Mar 14 at 15:56
$begingroup$
@yuri You are correct, I am a student that is learning object oriented programming right now. :)
$endgroup$
– Jon Frank
Mar 14 at 16:14
add a comment |
$begingroup$
I have finished my code for a "Virtual Zoo" game and I'm wondering how I would make the animals I added so far (Lion, Tiger, Bear) into sub classes so it's easier for me to add an animal in the future and the code would look neater.
My goal if possible would also be to add the attributes of 'health' and 'tiredness' to each animal through OOP.
Could someone show me how to make a parent class: animal with the attributes of tiredness and health while the subclasses lion, tiger, and bear can be subclasses?
<html>
<head>
<title>Virtual Pet</title>
<script>
// Virtual Pet Stats and starting values
// TODO: Change the name of your Virtual Pet on the line below.
var petName = "Virtual Pet";
var petStatus = "healthy";
var budget = 100000;
var profit = 0;
var totalLions = 0;
var totalTigers = 0;
var totalBears = 0;
var lionHealth = 60;
var maxLionHealth = 100;
var tigerHealth = 60;
var maxTigerHealth = 100;
var bearHealth = 60;
var maxBearHealth = 100;
var lionTiredness = 70;
var maxLionTiredness = 0;
var tigerTiredness = 70;
var maxTigerTiredness = 0;
var bearTiredness = 70;
var maxBearTiredness = 0;
/*var tiger = new animal("Tiger",0.5);
var lion = new animal("Lion",0.5);
var bear = new animal("Bear",1);
// TODO: Add more Virtual Pet stats that will be modified by your functions
function animal(name, profit) {
this.name = name;
this.profit = profit;
this.greeting = function() {
alert("You just bought a" + this.name + "He currently makes " + this.profit + "per second.");
};
};
*/
// Increases the current health of the Virtual Pet until it is maxed out.
function lion() {
if (budget >= 20000) {
budget -= 20000;
profit += 2.5;
totalLions += 1;
alert ("You just purchased a Lion, your profit has increased to " + profit + "$. You now own " + totalLions + " Lions.");
} else {
var difference = 20000 - budget;
alert ("You need " + difference + " more dollars to purchase a Lion.");
}
}
function tiger() {
if (budget >= 10000) {
budget -= 10000;
profit += 2.5;
totalTigers += 1;
alert ("You just purchased a Tiger, your profit has increased to " + profit + "$. You now own " + totalTigers + " Tigers.");
} else {
var difference = 10000 - budget;
alert ("You need " + difference + " more dollars to purchase a Tiger.");
}
}
function bear() {
if (budget >= 20000) {
budget -= 20000;
profit += 5;
totalBears += 1;
alert ("You just purchased a Bear, your profit has increased to " + profit + "$. You now own " + totalBears + " Bears.");
} else {
var difference = 20000 - budget;
alert ("You need " + difference + " more dollars to purchase a Bear.");
}
}
/*function exercise()
{
currentHealth = currentHealth + 5;
if(currentHealth > maxHealth)
{
currentHealth = maxHealth;
}
// Update the display after an action has occurred.
updateDisplay();
}
*/
function exercise() {
lionHealth = lionHealth + 6;
tigerHealth = tigerHealth + 4;
bearHealth = bearHealth + 4;
if (lionHealth > maxLionHealth)
{
lionHealth = maxLionHealth;
} if (tigerHealth > maxTigerHealth) {
tigerHealth = maxTigerHealth;
} if (bearHealth > maxBearHealth) {
bearHealth = maxBearHealth;
}
updateDisplay();
}
function sleep(){
lionTiredness = lionTiredness - 10;
tigerTiredness = tigerTiredness - 20;
bearTiredness = bearTiredness - 20;
if (lionTiredness < maxLionTiredness)
{
lionTiredness = maxLionTiredness;
} if (tigerTiredness < maxTigerTiredness) {
tigerTiredness = maxTigerTiredness;
} if (bearTiredness < maxBearTiredness) {
bearTiredness = maxBearTiredness;
}
updateDisplay();
}
// TODO: Write new functions that will process and modify the new stats you have created. (The majority of your new code should go here.)
// Modifies any stats that automatically change every few seconds.
// (For example, health decreases every few seconds so the play needs to occationally exercise their Virtual Pet)
function changesOverTime()
{
lionHealth = lionHealth - 7.5;
tigerHealth = tigerHealth - 5;
bearHealth = bearHealth - 5;
lionTiredness = lionTiredness + 25;
tigerTiredness = tigerTiredness + 5;
bearTiredness = bearTiredness + 5;
if (lionTiredness > 100)
{
lionTiredness = 100;
} if (tigerTiredness > 100) {
tigerTiredness = 100;
} if (bearTiredness > 100) {
bearTiredness = 100;
}
budget = budget + profit;
// TODO: Add in other changes to the Virtual Pet stats that occur on a regular basis.
}
// Checks the pet's health and modifies the status accordingly
function checkHealth()
{
if(lionHealth <= 0 || tigerHealth <= 0 || bearHealth <= 0)
{
petStatus = "Dead";
currentHealth = 0;
}
//TODO (Optional): Add other health status checks (For example, sick if health < 15)
}
// Displays a Title to the screen for your Virtual Pet game
function displayTitle()
{
// TODO (Optional): Create your own title
}
// Displays the current pet stats to the screen.
function displayPetStats()
{
document.write("<h2>" + petName + " Status: " + petStatus + "</h2>");
<!-- document.write("<p>Health = " + currentHealth + " Max Health = " + maxHealth + "</p>"); -->
<!-- document.write("<p>Tiredness = " + tiredness + " Max Tiredness = " + maxTiredness + "</p>"); -->
document.write("<p>Budget = " + budget);
document.write("<p>Profit per second = " + profit);
if (totalLions >= 1) {
document.write("<p>Total Lions = " + totalLions);
document.write("<p>Lion Health = " + lionHealth);
document.write("<p>Lion Tiredness = " + lionTiredness);
}
if (totalTigers >= 1) {
document.write("<p>Total Tigers = " + totalTigers);
document.write("<p>Tiger Health = " + tigerHealth);
document.write("<p>Tiger Tiredness = " + tigerTiredness);
}
if (totalBears >= 1) {
document.write("<p>Total Bears = " + totalBears);
document.write("<p>Bear Health = " + bearHealth);
document.write("<p>Bear Tiredness = " + bearTiredness);
}
// TODO: Add the display of new Virtual Pet stats here
document.close();
}
// Displays the buttons to the screen enabling the user to interact with their virtual pet.
function displayUserOptions()
{
if(petStatus != "Dead")
{
document.write("<button onclick='exercise()'>Exercise</button>");
document.write("<button onclick='sleep()'>Sleep</button>nnn");
document.write("<button onclick='tiger()'>Tiger</button>");
document.write("<button onclick='lion()'>Lion</button>");
document.write("<button onclick='bear()'>Bear</button>");
// TODO: Create buttons for other actions
}
}
// Calls all the functions that display information to the screen.
function updateDisplay()
{
displayTitle();
displayUserOptions();
displayPetStats();
}
// This function executes the game and manages the passing of time.
function gameLoop(timestamp)
{
document.body.style.backgroundColor = "#f3f3f3";
document.body.style.backgroundImage = "url('https://wallpapercave.com/wp/4W0u3iC.jpg')";
if(timestamp > last_iteration + time_interval)
{
last_iteration = timestamp;
changesOverTime();
checkHealth();
// TODO: Check other Virtual Pet stats and update the petStatus accordingly
// After all stats updates are done, update/recreate the display
updateDisplay();
}
// Life continues unless the Virtual Pet is dead (health <= 0)
if(petStatus != "Dead")
{
// Executes the gameLoop function once again.
requestAnimationFrame(gameLoop);
}
}
// Other global variables that control the timing of the game.
var time_interval = 5000;
var last_iteration = 0;
</script>
</head>
<h1>My Virtual Pet!</h1>
<!-- Initiate the gameLoop for the first time.-->
<button onclick='gameLoop()'>Bring my Virtual Pet to Life!</button>
</body>
</html>
javascript beginner object-oriented
$endgroup$
I have finished my code for a "Virtual Zoo" game and I'm wondering how I would make the animals I added so far (Lion, Tiger, Bear) into sub classes so it's easier for me to add an animal in the future and the code would look neater.
My goal if possible would also be to add the attributes of 'health' and 'tiredness' to each animal through OOP.
Could someone show me how to make a parent class: animal with the attributes of tiredness and health while the subclasses lion, tiger, and bear can be subclasses?
<html>
<head>
<title>Virtual Pet</title>
<script>
// Virtual Pet Stats and starting values
// TODO: Change the name of your Virtual Pet on the line below.
var petName = "Virtual Pet";
var petStatus = "healthy";
var budget = 100000;
var profit = 0;
var totalLions = 0;
var totalTigers = 0;
var totalBears = 0;
var lionHealth = 60;
var maxLionHealth = 100;
var tigerHealth = 60;
var maxTigerHealth = 100;
var bearHealth = 60;
var maxBearHealth = 100;
var lionTiredness = 70;
var maxLionTiredness = 0;
var tigerTiredness = 70;
var maxTigerTiredness = 0;
var bearTiredness = 70;
var maxBearTiredness = 0;
/*var tiger = new animal("Tiger",0.5);
var lion = new animal("Lion",0.5);
var bear = new animal("Bear",1);
// TODO: Add more Virtual Pet stats that will be modified by your functions
function animal(name, profit) {
this.name = name;
this.profit = profit;
this.greeting = function() {
alert("You just bought a" + this.name + "He currently makes " + this.profit + "per second.");
};
};
*/
// Increases the current health of the Virtual Pet until it is maxed out.
function lion() {
if (budget >= 20000) {
budget -= 20000;
profit += 2.5;
totalLions += 1;
alert ("You just purchased a Lion, your profit has increased to " + profit + "$. You now own " + totalLions + " Lions.");
} else {
var difference = 20000 - budget;
alert ("You need " + difference + " more dollars to purchase a Lion.");
}
}
function tiger() {
if (budget >= 10000) {
budget -= 10000;
profit += 2.5;
totalTigers += 1;
alert ("You just purchased a Tiger, your profit has increased to " + profit + "$. You now own " + totalTigers + " Tigers.");
} else {
var difference = 10000 - budget;
alert ("You need " + difference + " more dollars to purchase a Tiger.");
}
}
function bear() {
if (budget >= 20000) {
budget -= 20000;
profit += 5;
totalBears += 1;
alert ("You just purchased a Bear, your profit has increased to " + profit + "$. You now own " + totalBears + " Bears.");
} else {
var difference = 20000 - budget;
alert ("You need " + difference + " more dollars to purchase a Bear.");
}
}
/*function exercise()
{
currentHealth = currentHealth + 5;
if(currentHealth > maxHealth)
{
currentHealth = maxHealth;
}
// Update the display after an action has occurred.
updateDisplay();
}
*/
function exercise() {
lionHealth = lionHealth + 6;
tigerHealth = tigerHealth + 4;
bearHealth = bearHealth + 4;
if (lionHealth > maxLionHealth)
{
lionHealth = maxLionHealth;
} if (tigerHealth > maxTigerHealth) {
tigerHealth = maxTigerHealth;
} if (bearHealth > maxBearHealth) {
bearHealth = maxBearHealth;
}
updateDisplay();
}
function sleep(){
lionTiredness = lionTiredness - 10;
tigerTiredness = tigerTiredness - 20;
bearTiredness = bearTiredness - 20;
if (lionTiredness < maxLionTiredness)
{
lionTiredness = maxLionTiredness;
} if (tigerTiredness < maxTigerTiredness) {
tigerTiredness = maxTigerTiredness;
} if (bearTiredness < maxBearTiredness) {
bearTiredness = maxBearTiredness;
}
updateDisplay();
}
// TODO: Write new functions that will process and modify the new stats you have created. (The majority of your new code should go here.)
// Modifies any stats that automatically change every few seconds.
// (For example, health decreases every few seconds so the play needs to occationally exercise their Virtual Pet)
function changesOverTime()
{
lionHealth = lionHealth - 7.5;
tigerHealth = tigerHealth - 5;
bearHealth = bearHealth - 5;
lionTiredness = lionTiredness + 25;
tigerTiredness = tigerTiredness + 5;
bearTiredness = bearTiredness + 5;
if (lionTiredness > 100)
{
lionTiredness = 100;
} if (tigerTiredness > 100) {
tigerTiredness = 100;
} if (bearTiredness > 100) {
bearTiredness = 100;
}
budget = budget + profit;
// TODO: Add in other changes to the Virtual Pet stats that occur on a regular basis.
}
// Checks the pet's health and modifies the status accordingly
function checkHealth()
{
if(lionHealth <= 0 || tigerHealth <= 0 || bearHealth <= 0)
{
petStatus = "Dead";
currentHealth = 0;
}
//TODO (Optional): Add other health status checks (For example, sick if health < 15)
}
// Displays a Title to the screen for your Virtual Pet game
function displayTitle()
{
// TODO (Optional): Create your own title
}
// Displays the current pet stats to the screen.
function displayPetStats()
{
document.write("<h2>" + petName + " Status: " + petStatus + "</h2>");
<!-- document.write("<p>Health = " + currentHealth + " Max Health = " + maxHealth + "</p>"); -->
<!-- document.write("<p>Tiredness = " + tiredness + " Max Tiredness = " + maxTiredness + "</p>"); -->
document.write("<p>Budget = " + budget);
document.write("<p>Profit per second = " + profit);
if (totalLions >= 1) {
document.write("<p>Total Lions = " + totalLions);
document.write("<p>Lion Health = " + lionHealth);
document.write("<p>Lion Tiredness = " + lionTiredness);
}
if (totalTigers >= 1) {
document.write("<p>Total Tigers = " + totalTigers);
document.write("<p>Tiger Health = " + tigerHealth);
document.write("<p>Tiger Tiredness = " + tigerTiredness);
}
if (totalBears >= 1) {
document.write("<p>Total Bears = " + totalBears);
document.write("<p>Bear Health = " + bearHealth);
document.write("<p>Bear Tiredness = " + bearTiredness);
}
// TODO: Add the display of new Virtual Pet stats here
document.close();
}
// Displays the buttons to the screen enabling the user to interact with their virtual pet.
function displayUserOptions()
{
if(petStatus != "Dead")
{
document.write("<button onclick='exercise()'>Exercise</button>");
document.write("<button onclick='sleep()'>Sleep</button>nnn");
document.write("<button onclick='tiger()'>Tiger</button>");
document.write("<button onclick='lion()'>Lion</button>");
document.write("<button onclick='bear()'>Bear</button>");
// TODO: Create buttons for other actions
}
}
// Calls all the functions that display information to the screen.
function updateDisplay()
{
displayTitle();
displayUserOptions();
displayPetStats();
}
// This function executes the game and manages the passing of time.
function gameLoop(timestamp)
{
document.body.style.backgroundColor = "#f3f3f3";
document.body.style.backgroundImage = "url('https://wallpapercave.com/wp/4W0u3iC.jpg')";
if(timestamp > last_iteration + time_interval)
{
last_iteration = timestamp;
changesOverTime();
checkHealth();
// TODO: Check other Virtual Pet stats and update the petStatus accordingly
// After all stats updates are done, update/recreate the display
updateDisplay();
}
// Life continues unless the Virtual Pet is dead (health <= 0)
if(petStatus != "Dead")
{
// Executes the gameLoop function once again.
requestAnimationFrame(gameLoop);
}
}
// Other global variables that control the timing of the game.
var time_interval = 5000;
var last_iteration = 0;
</script>
</head>
<h1>My Virtual Pet!</h1>
<!-- Initiate the gameLoop for the first time.-->
<button onclick='gameLoop()'>Bring my Virtual Pet to Life!</button>
</body>
</html>
<html>
<head>
<title>Virtual Pet</title>
<script>
// Virtual Pet Stats and starting values
// TODO: Change the name of your Virtual Pet on the line below.
var petName = "Virtual Pet";
var petStatus = "healthy";
var budget = 100000;
var profit = 0;
var totalLions = 0;
var totalTigers = 0;
var totalBears = 0;
var lionHealth = 60;
var maxLionHealth = 100;
var tigerHealth = 60;
var maxTigerHealth = 100;
var bearHealth = 60;
var maxBearHealth = 100;
var lionTiredness = 70;
var maxLionTiredness = 0;
var tigerTiredness = 70;
var maxTigerTiredness = 0;
var bearTiredness = 70;
var maxBearTiredness = 0;
/*var tiger = new animal("Tiger",0.5);
var lion = new animal("Lion",0.5);
var bear = new animal("Bear",1);
// TODO: Add more Virtual Pet stats that will be modified by your functions
function animal(name, profit) {
this.name = name;
this.profit = profit;
this.greeting = function() {
alert("You just bought a" + this.name + "He currently makes " + this.profit + "per second.");
};
};
*/
// Increases the current health of the Virtual Pet until it is maxed out.
function lion() {
if (budget >= 20000) {
budget -= 20000;
profit += 2.5;
totalLions += 1;
alert ("You just purchased a Lion, your profit has increased to " + profit + "$. You now own " + totalLions + " Lions.");
} else {
var difference = 20000 - budget;
alert ("You need " + difference + " more dollars to purchase a Lion.");
}
}
function tiger() {
if (budget >= 10000) {
budget -= 10000;
profit += 2.5;
totalTigers += 1;
alert ("You just purchased a Tiger, your profit has increased to " + profit + "$. You now own " + totalTigers + " Tigers.");
} else {
var difference = 10000 - budget;
alert ("You need " + difference + " more dollars to purchase a Tiger.");
}
}
function bear() {
if (budget >= 20000) {
budget -= 20000;
profit += 5;
totalBears += 1;
alert ("You just purchased a Bear, your profit has increased to " + profit + "$. You now own " + totalBears + " Bears.");
} else {
var difference = 20000 - budget;
alert ("You need " + difference + " more dollars to purchase a Bear.");
}
}
/*function exercise()
{
currentHealth = currentHealth + 5;
if(currentHealth > maxHealth)
{
currentHealth = maxHealth;
}
// Update the display after an action has occurred.
updateDisplay();
}
*/
function exercise() {
lionHealth = lionHealth + 6;
tigerHealth = tigerHealth + 4;
bearHealth = bearHealth + 4;
if (lionHealth > maxLionHealth)
{
lionHealth = maxLionHealth;
} if (tigerHealth > maxTigerHealth) {
tigerHealth = maxTigerHealth;
} if (bearHealth > maxBearHealth) {
bearHealth = maxBearHealth;
}
updateDisplay();
}
function sleep(){
lionTiredness = lionTiredness - 10;
tigerTiredness = tigerTiredness - 20;
bearTiredness = bearTiredness - 20;
if (lionTiredness < maxLionTiredness)
{
lionTiredness = maxLionTiredness;
} if (tigerTiredness < maxTigerTiredness) {
tigerTiredness = maxTigerTiredness;
} if (bearTiredness < maxBearTiredness) {
bearTiredness = maxBearTiredness;
}
updateDisplay();
}
// TODO: Write new functions that will process and modify the new stats you have created. (The majority of your new code should go here.)
// Modifies any stats that automatically change every few seconds.
// (For example, health decreases every few seconds so the play needs to occationally exercise their Virtual Pet)
function changesOverTime()
{
lionHealth = lionHealth - 7.5;
tigerHealth = tigerHealth - 5;
bearHealth = bearHealth - 5;
lionTiredness = lionTiredness + 25;
tigerTiredness = tigerTiredness + 5;
bearTiredness = bearTiredness + 5;
if (lionTiredness > 100)
{
lionTiredness = 100;
} if (tigerTiredness > 100) {
tigerTiredness = 100;
} if (bearTiredness > 100) {
bearTiredness = 100;
}
budget = budget + profit;
// TODO: Add in other changes to the Virtual Pet stats that occur on a regular basis.
}
// Checks the pet's health and modifies the status accordingly
function checkHealth()
{
if(lionHealth <= 0 || tigerHealth <= 0 || bearHealth <= 0)
{
petStatus = "Dead";
currentHealth = 0;
}
//TODO (Optional): Add other health status checks (For example, sick if health < 15)
}
// Displays a Title to the screen for your Virtual Pet game
function displayTitle()
{
// TODO (Optional): Create your own title
}
// Displays the current pet stats to the screen.
function displayPetStats()
{
document.write("<h2>" + petName + " Status: " + petStatus + "</h2>");
<!-- document.write("<p>Health = " + currentHealth + " Max Health = " + maxHealth + "</p>"); -->
<!-- document.write("<p>Tiredness = " + tiredness + " Max Tiredness = " + maxTiredness + "</p>"); -->
document.write("<p>Budget = " + budget);
document.write("<p>Profit per second = " + profit);
if (totalLions >= 1) {
document.write("<p>Total Lions = " + totalLions);
document.write("<p>Lion Health = " + lionHealth);
document.write("<p>Lion Tiredness = " + lionTiredness);
}
if (totalTigers >= 1) {
document.write("<p>Total Tigers = " + totalTigers);
document.write("<p>Tiger Health = " + tigerHealth);
document.write("<p>Tiger Tiredness = " + tigerTiredness);
}
if (totalBears >= 1) {
document.write("<p>Total Bears = " + totalBears);
document.write("<p>Bear Health = " + bearHealth);
document.write("<p>Bear Tiredness = " + bearTiredness);
}
// TODO: Add the display of new Virtual Pet stats here
document.close();
}
// Displays the buttons to the screen enabling the user to interact with their virtual pet.
function displayUserOptions()
{
if(petStatus != "Dead")
{
document.write("<button onclick='exercise()'>Exercise</button>");
document.write("<button onclick='sleep()'>Sleep</button>nnn");
document.write("<button onclick='tiger()'>Tiger</button>");
document.write("<button onclick='lion()'>Lion</button>");
document.write("<button onclick='bear()'>Bear</button>");
// TODO: Create buttons for other actions
}
}
// Calls all the functions that display information to the screen.
function updateDisplay()
{
displayTitle();
displayUserOptions();
displayPetStats();
}
// This function executes the game and manages the passing of time.
function gameLoop(timestamp)
{
document.body.style.backgroundColor = "#f3f3f3";
document.body.style.backgroundImage = "url('https://wallpapercave.com/wp/4W0u3iC.jpg')";
if(timestamp > last_iteration + time_interval)
{
last_iteration = timestamp;
changesOverTime();
checkHealth();
// TODO: Check other Virtual Pet stats and update the petStatus accordingly
// After all stats updates are done, update/recreate the display
updateDisplay();
}
// Life continues unless the Virtual Pet is dead (health <= 0)
if(petStatus != "Dead")
{
// Executes the gameLoop function once again.
requestAnimationFrame(gameLoop);
}
}
// Other global variables that control the timing of the game.
var time_interval = 5000;
var last_iteration = 0;
</script>
</head>
<h1>My Virtual Pet!</h1>
<!-- Initiate the gameLoop for the first time.-->
<button onclick='gameLoop()'>Bring my Virtual Pet to Life!</button>
</body>
</html>
<html>
<head>
<title>Virtual Pet</title>
<script>
// Virtual Pet Stats and starting values
// TODO: Change the name of your Virtual Pet on the line below.
var petName = "Virtual Pet";
var petStatus = "healthy";
var budget = 100000;
var profit = 0;
var totalLions = 0;
var totalTigers = 0;
var totalBears = 0;
var lionHealth = 60;
var maxLionHealth = 100;
var tigerHealth = 60;
var maxTigerHealth = 100;
var bearHealth = 60;
var maxBearHealth = 100;
var lionTiredness = 70;
var maxLionTiredness = 0;
var tigerTiredness = 70;
var maxTigerTiredness = 0;
var bearTiredness = 70;
var maxBearTiredness = 0;
/*var tiger = new animal("Tiger",0.5);
var lion = new animal("Lion",0.5);
var bear = new animal("Bear",1);
// TODO: Add more Virtual Pet stats that will be modified by your functions
function animal(name, profit) {
this.name = name;
this.profit = profit;
this.greeting = function() {
alert("You just bought a" + this.name + "He currently makes " + this.profit + "per second.");
};
};
*/
// Increases the current health of the Virtual Pet until it is maxed out.
function lion() {
if (budget >= 20000) {
budget -= 20000;
profit += 2.5;
totalLions += 1;
alert ("You just purchased a Lion, your profit has increased to " + profit + "$. You now own " + totalLions + " Lions.");
} else {
var difference = 20000 - budget;
alert ("You need " + difference + " more dollars to purchase a Lion.");
}
}
function tiger() {
if (budget >= 10000) {
budget -= 10000;
profit += 2.5;
totalTigers += 1;
alert ("You just purchased a Tiger, your profit has increased to " + profit + "$. You now own " + totalTigers + " Tigers.");
} else {
var difference = 10000 - budget;
alert ("You need " + difference + " more dollars to purchase a Tiger.");
}
}
function bear() {
if (budget >= 20000) {
budget -= 20000;
profit += 5;
totalBears += 1;
alert ("You just purchased a Bear, your profit has increased to " + profit + "$. You now own " + totalBears + " Bears.");
} else {
var difference = 20000 - budget;
alert ("You need " + difference + " more dollars to purchase a Bear.");
}
}
/*function exercise()
{
currentHealth = currentHealth + 5;
if(currentHealth > maxHealth)
{
currentHealth = maxHealth;
}
// Update the display after an action has occurred.
updateDisplay();
}
*/
function exercise() {
lionHealth = lionHealth + 6;
tigerHealth = tigerHealth + 4;
bearHealth = bearHealth + 4;
if (lionHealth > maxLionHealth)
{
lionHealth = maxLionHealth;
} if (tigerHealth > maxTigerHealth) {
tigerHealth = maxTigerHealth;
} if (bearHealth > maxBearHealth) {
bearHealth = maxBearHealth;
}
updateDisplay();
}
function sleep(){
lionTiredness = lionTiredness - 10;
tigerTiredness = tigerTiredness - 20;
bearTiredness = bearTiredness - 20;
if (lionTiredness < maxLionTiredness)
{
lionTiredness = maxLionTiredness;
} if (tigerTiredness < maxTigerTiredness) {
tigerTiredness = maxTigerTiredness;
} if (bearTiredness < maxBearTiredness) {
bearTiredness = maxBearTiredness;
}
updateDisplay();
}
// TODO: Write new functions that will process and modify the new stats you have created. (The majority of your new code should go here.)
// Modifies any stats that automatically change every few seconds.
// (For example, health decreases every few seconds so the play needs to occationally exercise their Virtual Pet)
function changesOverTime()
{
lionHealth = lionHealth - 7.5;
tigerHealth = tigerHealth - 5;
bearHealth = bearHealth - 5;
lionTiredness = lionTiredness + 25;
tigerTiredness = tigerTiredness + 5;
bearTiredness = bearTiredness + 5;
if (lionTiredness > 100)
{
lionTiredness = 100;
} if (tigerTiredness > 100) {
tigerTiredness = 100;
} if (bearTiredness > 100) {
bearTiredness = 100;
}
budget = budget + profit;
// TODO: Add in other changes to the Virtual Pet stats that occur on a regular basis.
}
// Checks the pet's health and modifies the status accordingly
function checkHealth()
{
if(lionHealth <= 0 || tigerHealth <= 0 || bearHealth <= 0)
{
petStatus = "Dead";
currentHealth = 0;
}
//TODO (Optional): Add other health status checks (For example, sick if health < 15)
}
// Displays a Title to the screen for your Virtual Pet game
function displayTitle()
{
// TODO (Optional): Create your own title
}
// Displays the current pet stats to the screen.
function displayPetStats()
{
document.write("<h2>" + petName + " Status: " + petStatus + "</h2>");
<!-- document.write("<p>Health = " + currentHealth + " Max Health = " + maxHealth + "</p>"); -->
<!-- document.write("<p>Tiredness = " + tiredness + " Max Tiredness = " + maxTiredness + "</p>"); -->
document.write("<p>Budget = " + budget);
document.write("<p>Profit per second = " + profit);
if (totalLions >= 1) {
document.write("<p>Total Lions = " + totalLions);
document.write("<p>Lion Health = " + lionHealth);
document.write("<p>Lion Tiredness = " + lionTiredness);
}
if (totalTigers >= 1) {
document.write("<p>Total Tigers = " + totalTigers);
document.write("<p>Tiger Health = " + tigerHealth);
document.write("<p>Tiger Tiredness = " + tigerTiredness);
}
if (totalBears >= 1) {
document.write("<p>Total Bears = " + totalBears);
document.write("<p>Bear Health = " + bearHealth);
document.write("<p>Bear Tiredness = " + bearTiredness);
}
// TODO: Add the display of new Virtual Pet stats here
document.close();
}
// Displays the buttons to the screen enabling the user to interact with their virtual pet.
function displayUserOptions()
{
if(petStatus != "Dead")
{
document.write("<button onclick='exercise()'>Exercise</button>");
document.write("<button onclick='sleep()'>Sleep</button>nnn");
document.write("<button onclick='tiger()'>Tiger</button>");
document.write("<button onclick='lion()'>Lion</button>");
document.write("<button onclick='bear()'>Bear</button>");
// TODO: Create buttons for other actions
}
}
// Calls all the functions that display information to the screen.
function updateDisplay()
{
displayTitle();
displayUserOptions();
displayPetStats();
}
// This function executes the game and manages the passing of time.
function gameLoop(timestamp)
{
document.body.style.backgroundColor = "#f3f3f3";
document.body.style.backgroundImage = "url('https://wallpapercave.com/wp/4W0u3iC.jpg')";
if(timestamp > last_iteration + time_interval)
{
last_iteration = timestamp;
changesOverTime();
checkHealth();
// TODO: Check other Virtual Pet stats and update the petStatus accordingly
// After all stats updates are done, update/recreate the display
updateDisplay();
}
// Life continues unless the Virtual Pet is dead (health <= 0)
if(petStatus != "Dead")
{
// Executes the gameLoop function once again.
requestAnimationFrame(gameLoop);
}
}
// Other global variables that control the timing of the game.
var time_interval = 5000;
var last_iteration = 0;
</script>
</head>
<h1>My Virtual Pet!</h1>
<!-- Initiate the gameLoop for the first time.-->
<button onclick='gameLoop()'>Bring my Virtual Pet to Life!</button>
</body>
</html>
javascript beginner object-oriented
javascript beginner object-oriented
edited Mar 14 at 14:17
Jon Frank
asked Mar 14 at 13:09
Jon FrankJon Frank
72
72
closed as off-topic by yuri, Gerrit0, Toby Speight, Zeta, Mast Mar 14 at 21:02
This question appears to be off-topic. The users who voted to close gave these specific reasons:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Toby Speight, Zeta, Mast
- "Authorship of code: Since Code Review is a community where programmers improve their skills through peer review, we require that the code be posted by an author or maintainer of the code, that the code be embedded directly, and that the poster know why the code is written the way it is." – yuri, Gerrit0
If this question can be reworded to fit the rules in the help center, please edit the question.
closed as off-topic by yuri, Gerrit0, Toby Speight, Zeta, Mast Mar 14 at 21:02
This question appears to be off-topic. The users who voted to close gave these specific reasons:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Toby Speight, Zeta, Mast
- "Authorship of code: Since Code Review is a community where programmers improve their skills through peer review, we require that the code be posted by an author or maintainer of the code, that the code be embedded directly, and that the poster know why the code is written the way it is." – yuri, Gerrit0
If this question can be reworded to fit the rules in the help center, please edit the question.
$begingroup$
It there a reason you are not using es6 classes?
$endgroup$
– Michael Warner
Mar 14 at 13:13
1
$begingroup$
The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to simply state the task accomplished by the code. Please see How to get the best value out of Code Review - Asking Questions for guidance on writing good question titles.
$endgroup$
– BCdotWEB
Mar 14 at 13:20
$begingroup$
@MichaelWarner because I am new to Javascript, im trying to see an example of how to do this with the script I wrote.
$endgroup$
– Jon Frank
Mar 14 at 13:34
2
$begingroup$
This looks like unfinished homework.
$endgroup$
– yuri
Mar 14 at 15:56
$begingroup$
@yuri You are correct, I am a student that is learning object oriented programming right now. :)
$endgroup$
– Jon Frank
Mar 14 at 16:14
add a comment |
$begingroup$
It there a reason you are not using es6 classes?
$endgroup$
– Michael Warner
Mar 14 at 13:13
1
$begingroup$
The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to simply state the task accomplished by the code. Please see How to get the best value out of Code Review - Asking Questions for guidance on writing good question titles.
$endgroup$
– BCdotWEB
Mar 14 at 13:20
$begingroup$
@MichaelWarner because I am new to Javascript, im trying to see an example of how to do this with the script I wrote.
$endgroup$
– Jon Frank
Mar 14 at 13:34
2
$begingroup$
This looks like unfinished homework.
$endgroup$
– yuri
Mar 14 at 15:56
$begingroup$
@yuri You are correct, I am a student that is learning object oriented programming right now. :)
$endgroup$
– Jon Frank
Mar 14 at 16:14
$begingroup$
It there a reason you are not using es6 classes?
$endgroup$
– Michael Warner
Mar 14 at 13:13
$begingroup$
It there a reason you are not using es6 classes?
$endgroup$
– Michael Warner
Mar 14 at 13:13
1
1
$begingroup$
The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to simply state the task accomplished by the code. Please see How to get the best value out of Code Review - Asking Questions for guidance on writing good question titles.
$endgroup$
– BCdotWEB
Mar 14 at 13:20
$begingroup$
The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to simply state the task accomplished by the code. Please see How to get the best value out of Code Review - Asking Questions for guidance on writing good question titles.
$endgroup$
– BCdotWEB
Mar 14 at 13:20
$begingroup$
@MichaelWarner because I am new to Javascript, im trying to see an example of how to do this with the script I wrote.
$endgroup$
– Jon Frank
Mar 14 at 13:34
$begingroup$
@MichaelWarner because I am new to Javascript, im trying to see an example of how to do this with the script I wrote.
$endgroup$
– Jon Frank
Mar 14 at 13:34
2
2
$begingroup$
This looks like unfinished homework.
$endgroup$
– yuri
Mar 14 at 15:56
$begingroup$
This looks like unfinished homework.
$endgroup$
– yuri
Mar 14 at 15:56
$begingroup$
@yuri You are correct, I am a student that is learning object oriented programming right now. :)
$endgroup$
– Jon Frank
Mar 14 at 16:14
$begingroup$
@yuri You are correct, I am a student that is learning object oriented programming right now. :)
$endgroup$
– Jon Frank
Mar 14 at 16:14
add a comment |
0
active
oldest
votes
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
It there a reason you are not using es6 classes?
$endgroup$
– Michael Warner
Mar 14 at 13:13
1
$begingroup$
The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to simply state the task accomplished by the code. Please see How to get the best value out of Code Review - Asking Questions for guidance on writing good question titles.
$endgroup$
– BCdotWEB
Mar 14 at 13:20
$begingroup$
@MichaelWarner because I am new to Javascript, im trying to see an example of how to do this with the script I wrote.
$endgroup$
– Jon Frank
Mar 14 at 13:34
2
$begingroup$
This looks like unfinished homework.
$endgroup$
– yuri
Mar 14 at 15:56
$begingroup$
@yuri You are correct, I am a student that is learning object oriented programming right now. :)
$endgroup$
– Jon Frank
Mar 14 at 16:14