cclloyd9785 Posted July 12, 2011 Share Posted July 12, 2011 I had this script Scour Level: <input type="text" id="level" size="1" onchange="scour(this.value);"/> <button on click="scour(this.value);" /> Calculate! </button><br /><br /> <script type="text/javascript"> function scour(level){ var level = document.getElementById('level').value; var a = Math.floor(4+level/3) var b = Math.floor(100-(100*4/a)) alert("Yor scour level is " + '\n' + '\n' + "The chance of boxes at level " + level + " is " + b);} </script> And then changed it to Scour Level: <input type="text" id="level" size="1" onchange="scour(this.value);"/> <button on click="scour(this.value);" /> Calculate! </button><br /><br /> <script type="text/javascript"> function scour(level){ var level = document.getElementById('level').value; var a = Math.pow(level,3); var b = Math.(125*a); alert("Yor scour level is " + level + '\n' + '\n' + "<br><br>The experience required to reach level " + level + " is: " + b)} </script> And now it doesn't work. I feel like its a problem with the math because when I replaced the math elements with the ones in the first one, it worked again. Any idea why it wont work? Link to comment Share on other sites More sharing options...
justsomeguy Posted July 12, 2011 Share Posted July 12, 2011 What is this supposed to be:var b = Math.(125*a);Also, why are you getting the value in the function if you're passing the value to the function? Link to comment Share on other sites More sharing options...
cclloyd9785 Posted July 12, 2011 Author Share Posted July 12, 2011 What is this supposed to be:var b = Math.(125*a);Also, why are you getting the value in the function if you're passing the value to the function?I don't know what you mean. Im very new, and just copied part of the code from somewhere else.But that was me trying to get the math to work since other formulas werent working unless I broke it up into parts.The full formula is EXP = 125*pow(level,3)Just like this one:$price = min(1000000,100*floor( ($fcnt-9)*pow(1.2, $fcnt-10)));I had to break it up to get it to work.EDIT: Fixed. It needed a Math. before the pow for some reason...Still, if anyone can help me optimize this code, it would be appreciated. Link to comment Share on other sites More sharing options...
justsomeguy Posted July 12, 2011 Share Posted July 12, 2011 Im very new, and just copied part of the code from somewhere else.That's part of the problem then, you probably haven't looked up how to do arithmetic in Javascript. That's covered in the section on operators:http://www.w3schools.com/js/js_operators.aspThe Math object is just for math functions, like round, floor, etc. You don't need the Math object for basic arithmetic:var b = 125 * a; Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.