Having trouble understanding scope and variables using DOM in Javascript -
i working on hangman game using javascript only. class. noob @ javascript , dom please kind. @ point, want print out something, really, in console log. have been @ days , hours removing of functions , game processes except few shown here try work. thought process variables not change within loop , not need dynamically updated in html not need properties of hangman game. but, when run following code working console.log, userguess not defined. thought defining assigning value of keyup event. if make userguess property of hangman game , update rest of code hangmangame.userguess, of these unexpected token errors.
any thoughts?
//variables=============================================================== var hangmangame = {presidents: [ "washington", "adams", "jefferson", "madison", "monroe", "jackson", "vanburen", "harrison", "tyler", "polk", "taylor", "fillmore", "pierce", "buchanan", "lincoln", "johnson", "grant", "hayes", "garfield", "arthur", "cleveland", "harrison", "mckinley", "roosevelt", "taft", "wilson", "harding", "coolidge", "hoover", "truman", "eisenhower", "kennedy", "nixon", "ford", "carter", "reagan", "bush", "clinton", "obama" ], wrongallowed: 7, goodletters: 0, wordarray: [], badarray: [], wins: 0, //functions========================================================= startgame: function() { var word = hangmangame.presidents[math.floor(math.random() * hangmangame.presidents.length)]; }, } function write() { console.log("president" + word); } //main process=============================== document.onkeyup = function(event) { var userguess = string.fromcharcode(event.keycode).touppercase(); } if (userguess == 'a'){ write(); }
change this
// main process document.onkeyup = function(event) { var userguess = string.fromcharcode(event.keycode).touppercase(); if (userguess === 'a') { write(); } }
Comments
Post a Comment