I'm building a functionality on my "pig game", so the user can set himself the winning value if he wish, by entering it in an input field.
I need to use the value the user enter in an <input type="text">
, in order to change a behavior in my JavaScript code.
I wrote my input as :
<div class ="newInputScore">
<label for="fixGoal">SET THE GOAL :</label><br>
<input name = "fixGoal" type = "text" id = "fixGoal">
</div>
and I need to use the value the user write in the above input, in my JS code. So far, I tried :
let choosenScore = parseInt(document.getElementById('fixGoal').value);
if (scores[activePlayer] >= 100 || scores[activePlayer] >= choosenScore){...
... but it seems like my input is returning me a value of 0, because the player is actually winning with a score > 0 with the above code. I console log()'ed choosenScore and it returns me NaN, then undefined on the line below. What am I missing there? Thanks in advance.
link to the project (dices don't appears because files are on my computer) : https://codepen.io/Peyo5202/pen/dybqyXV