Javascript Calculator
I am making a Level calculator for a game.
The only problem is, is that i cant figure out whats wrong.
PHP Code:
function fmtPrice ( wos , kos )
{
if ( wos = 0 )
{
wos = 1
}
result = "" ;
result += Math . floor ( kos /try);
return result ;
}
function compute () {
var kd = document . forms [ 0 ]. KOs . value ;
var wd = document . forms [ 0 ]. WOs . value ;
var Level = fmtPrice ( wd , kd );
document . forms [ 0 ]. Level . value = Level ;
}
function resetIt () {
document . forms [ 0 ]. cost . value = "0" ;
document . forms [ 0 ]. tax . value = "0" ;
}
New Code Edit.
Last edited by Kevin's Dog; 12-07-2009 at 11:38 AM .
Don't indicate what errors are, but my guess is here:
change to:
And let us know what happens.
Originally Posted by
JMRKER
Don't indicate what errors are, but my guess is here:
change to:
And let us know what happens.
Sorry about the No Errors.
I dont have a javascript debugging program though D:
I'll go and see what happens.
I just tried that.
Bottom left corner of my IE says Error on page.
What should i do know?
Do you think i should add in:
Code:
var Wsd = " " + wos
?
Im not sure, this is my FIRST time experementing with javascript.
I added a few "Touches" to my source code, and it STILL dont work.
PHP Code:
function fmtPrice ( wos , kos ) result = "" ; result += Math . floor ( kos /try); if ( result == "Infinity" ) { result = "N0N" ; } else { result += "/50" ; } return result ; } function compute () { var kd = document . forms [ 0 ]. KOs . value ; var wd = document . forms [ 0 ]. WOs . value ; var Level = fmtPrice ( wd , kd ); var Reply = "Your PWning Level: " + Level + "/50" ; document . forms [ 0 ]. Level . value = Level ; } function resetIt () { document . forms [ 0 ]. WOs . value = "0" ; document . forms [ 0 ]. KOs . value = "0" ; }
Originally Posted by
Kevin's Dog
...I dont have a javascript debugging program though....
If you have Firefox install the Firebug pluggin - it is the best JavaScript debugger out right now.
OR
If you have IE8 just hit F12 to bring up "IE Developers Tools", click on the script tab and start debugging.
P.S.
Code:
function fmtPrice(wos,kos)
Has no starting "{" to enclose the function
AND in
Code:
result += Math.floor(kos/try );
The variable "try" is never defined to be anything AND "try" is a reserved JavaScript keyword (try/catch statement - http://www.w3schools.com/js/js_try_catch.asp )
Originally Posted by
slaughters
If you have Firefox install the Firebug pluggin - it is the best JavaScript debugger out right now.
OR
If you have IE8 just hit F12 to bring up "IE Developers Tools", click on the script tab and start debugging.
P.S.
Code:
function fmtPrice(wos,kos)
Has no starting "{" to enclose the function
AND in
Code:
result += Math.floor(kos/try );
The variable "try" is never defined to be anything AND "try" is a reserved JavaScript keyword (try/catch statement -
http://www.w3schools.com/js/js_try_catch.asp)
Thanks, but now This part of the code is woriking incorrectly.
Code:
function resetIt() {
var Blah= "0/50"
document.forms[0].WOs.value="0";
document.forms[0].KOs.value="0";
document.forms[0].Level.value=Blah;
}
The Level TextBox remains blank.
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Bookmarks