I need to change the variable after the submission form without reloading. So that I can next time get new num1 and num2 veritable with new correntAns and can check the correct answer.
Please see my code here; I need correctAns variable change after the submission form every time.
formEl.addEventListener("submit", function(evt){
evt.preventDefault();
const userAns = +inputEl.value;
//console.log(userAns, typeof userAns);
inputEl.value = "";
inputEl.focus();
if(userAns === correntAns){
score++;
submitCount++;
const num1 = Math.ceil(Math.random()*10);
const num2 = Math.ceil(Math.random()*10);
let correntAns = num1 * num2;
}else{
// score--;
submitCount++;
}
scoreEl.innerText = `Score: ${score}/${submitCount}`;
});
Use jQuery AJAX or XML ajax to submit the form without loading
you can change variable after form submission without loading in AJAX