By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,011 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

How do i fix a number after some point

P: 1
So here's the deal see this code?

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <title>Page Title</title>
  5. </head>
  6. <body>
  7. <h3><button onclick="a"> Aki attack</button> Aki hp <span id="b"> 200 </span></h3>
  8. <h3><button onclick="c (1)">Dark attack</button>Dark HP <span id="d"> 3500</span></h3>
  9. <script>
  10. var b=200;
  11.  
  12. var d=3500;
  13.  
  14. function c (number) { 
  15. b = b - 100;
  16. document.getElementById ("b").innerHTML =b;
  17. };
  18.  if (b < 0) {console.log(Math.sign(0));}; 
  19. </script>
  20.  
  21.  
  22. </body>
  23. </html>
i want to make "b" be 0 whenever the variable reaches a number under 0, like a fixed value, but i dont know why its not working
Jan 2 '19 #1
Share this Question
Share on Google+
1 Reply


gits
Expert Mod 5K+
P: 5,270
its not working because you dont set b back to 0 in case its value goes below 0.
Jan 4 '19 #2

Post your reply

Sign in to post your reply or Sign up for a free account.