Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

bug help?

Status
Not open for further replies.

chessbot

Programmer
Mar 14, 2004
1,524
US
I am writing an all-text Javascript game and I need debugging help. Could someone tell me the problem with this?

Here is a function in the beginning of the file. What it should do is see if "player.level" is 1. If so, it returns 10. Otherwise, it returns the triangle number equal to its level*100
(n)(n+1)/2 is the formula for triangle numbers

function getExp()
{
if (player.level==1)
{
var exp=10
}else{
var exp=(50*player.level)*(player.level+1)
}
alert(exp)
return exp
}

When I call the function like this
alert(getExp())
the page refreshes.
Help?
 
Take the dot out of player.level and it works. ie: playerlevel.
 
works fine for me:

Code:
<script type="text/javascript">
var player = {level:2}
		
function getExp()
{
    if (player.level==1)
    {
        var exp=10
    }else{
        var exp=(50*player.level)*(player.level+1)
    }
    alert(exp)
    return exp
}
</script>

<input type="button" value="getExp();" onclick="getExp();" />

perhaps the error is elsewhere in your page? how are you calling the function?

=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 
sorry about that, I realized my problem

i already had a function called getExp

d'oh
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top