Quantcast
Channel: Latest Questions on Unity Answers
Viewing all articles
Browse latest Browse all 171066

Help with JS Game

$
0
0
Hi, I'm building my first game in Unity with Javascript that is 2d. I currently can get everything, but my code right. I have been working with some different code editors such as Notepad++ and Codecademy Labs, but I run into a problem every time. Whenever I try to execute my code the alerts and prompts will continuously pop up despite the fact that my var, "enemyhealth" has already reached 0. Please help, I am under a nearing deadline that is closing in on me and I am trying to deliver on time for 4th grade math students that I can keep building on if the bugs can be worked out. Thanks, var enemyhealth = 10; var health = 5; alert("Welcome to the Battle Area!"); alert("This is the where you will fight your enemies with your knowledge of math! "); alert("Here comes the first one! Solve it quick, before he has a chance to hit you!"); alert ("10 + 8 + 2 - 5"); var strike = prompt("What is the answer?"); switch(strike){ case '15': enemyhealth - 1 alert("You dealt damage!"); break; default: health - 1 alert("You missed, he had the time to hit you!"); break; } alert ("7 * 5"); var strike2 = prompt("What is the answer?"); switch(strike2){ case '35': enemyhealth - 2 alert("You dealt damage!"); break; default: health - 1 alert("You missed, he had the time to hit you!"); break; } alert ("14 + 8 - 11 + 2"); var strike2 = prompt("What is the answer?"); switch(strike2){ case '13': enemyhealth - 2 alert("You dealt damage!"); break; default: health - 1 alert("You missed, he had the time to hit you!"); break; } alert ("100 / 4"); var strike2 = prompt("What is the answer?"); switch(strike2){ case '25': enemyhealth - 2 alert("You dealt damage!"); break; default: health - 1 alert("You missed, he had the time to hit you!"); break; } alert ("47 + 22 - 6 + 10"); var strike2 = prompt("What is the answer?"); switch(strike2){ case '63': enemyhealth - 2 alert("You dealt damage!"); break; default: health - 1 alert("You missed, he had the time to hit you!"); break; } if (enemyhealth == 0){ alert("You won! You beat your first enemy!"); } else{ alert ("19 + 49 + 10"); var strike2 = prompt("What is the answer?"); switch(strike2){ case '78': enemyhealth - 2 alert("You dealt damage!"); break; default: health - 1 alert("You missed, he had the time to hit you!"); break; } } if (enemyhealth == 0){ alert("You won! You beat your first enemy!"); } else{ alert ("63 - 32"); var strike2 = prompt("What is the answer?"); switch(strike2){ case '31': enemyhealth - 2 alert("You dealt damage!"); break; default: health - 1 alert("You missed, he had the time to hit you!"); break; } }

Viewing all articles
Browse latest Browse all 171066

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>