Jump to content

Math not working.


cclloyd9785
 Share

Recommended Posts

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

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. Edited by cclloyd
Link to comment
Share on other sites

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...