javascript - can't compare var of type int in conditional statements -


i declare global var in script sitting in head:

var nummonsters; 

then have setup div form call js function located in head , there assigning var:

 nummonsters = parseint(document.getelementbyid("monsters").value , 10); 

this element of setup div.

later replace divs display property : none/block

the new div contain js game, there want use value of global var, won't stand simple conditional statement, chrome debugger shows correct value, , seems defined it's realy not:

board = new array(); (var = 0; < 10; i++) {     board[i] = new array();     (var j = 0; j < 10; j++) {         board[i][j] = new array();          if ((i == 0) && (j == 0) && (nummonsters > 0)) {             board[i][j][1] = true;             board[i][j][2] = "red";         }         else if ((i == 9) && (j == 0) && (nummonsters > 1)) {             board[i][j][1] = true;             board[i][j][2] = "blue";         }         else if ((i == 9) && (j == 9) && (nummonsters > 2)) {             board[i][j][1] = true;             board[i][j][2] = "yellow";         }         else {             board[i][j][1] = false;         }     } } 

this var gets 1 of {0,1,2,3} values if considering i, j coordinates , placing true it's doing work it's nummonsters wo'nt function, , mentioned chrome debugger shows value it. it's droving me crazy, doing wrong?! doing same approach other vars , seems work fine. thanks

that working fine. else in code causing problem. can post of surrounding code?

fiddle

html

monsters: <input id="monsters" type="text" value="10"/> 

javascript

var nummonsters = parseint(document.getelementbyid("monsters").value, 10);  if (nummonsters > 0) {     alert("monsters win! variable " + typeof nummonsters); } else {     alert("fail."); } 

edit: code not work because "monsters" element not exist in dom @ point trying reference it.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -