javascript - Get an INPUT value from HTML Input -
i trying make guessing game. below repo on github. https://github.com/christsapphire/guessing-game
i wrote logic in guessing-game.js , worked fine. using userguess = prompt("guess number"). however, if click cancel on prompt, keep asking (maybe thats why??).
i tried translate jquery, using userguess = $('#input').val(); , encountered bug. webpage crashed after click "submit" button.
i want when user click "submit" button on webpage, runs function below.
function checkuserinput() { (var valid = false; !valid;) { //i suspect these 2 below // userguess = parseint($('#submit').val(), 10) //userguess = parseint(prompt("guess number"), 10); //----------- if ((userguess >= 1) && (userguess <= 100)) { if (repeatanswer(userguess, userguesshistory)) { $('#status').text("you chose number before! choose number!"); } else { valid = true; userguesshistory.push(userguess); return true; } } else { $('#status').text("that number invalid! please enter number between 1-100"); } } }
i think when enable userguess = $('#submit').val() repeatedly trying take input value input html element, crashed.
please help! before
it looks wanting value of input, not submit button:
$("#input").val();
are trying attach function submit button? be:
$("#submit").click(function(){ checkuserinput(); });
Comments
Post a Comment