• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Jan 27, 2014 at 11:00 PM by Graham-Dunnett for the following reason:

Question is off-topic or not relevant - not Unity related

avatar image
-1
Question by TruittW1225 · Jan 27, 2014 at 08:29 PM · 2d

Help with JS Game

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;
 }
 }
  
Comment
Comments Locked · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image AlucardJay · Jan 27, 2014 at 08:39 PM 1
Share

For any help, please format your code. You can do this by highlighting all your code, then clicking the 10101 button at the top of the edit window.

  • Read this page : http://answers.unity3d.com/page/newuser.html

  • Watch : http://video.unity3d.com/video/7720450/tutorials-using-unity-answers

0 Replies

  • Sort: 

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

2D Animation does not start 1 Answer

Assets/Scripts/PlayerController.cs(32,49): error CS0126: An object of a type convertible to `float' is required for the return statement 1 Answer

Sprite with non-constant jitter during constant velocity movement. 2 Answers

Basic 2D softbodies 0 Answers

Player movement boudaries in 2D 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges