+ 3
Why the 'x' variable not getting the Fresh Value
<script> function start(){ var fst = document.getElementById("fst").innerHTML = Math.floor(Math.random()*10); var snd = document.getElementById("snd").innerHTML = Math.floor(Math.random()*10); return fst+snd; } var x = start() function validate(){ var txt = document.getElementById("txt").value; if(txt==x){ console.log('Correct Answer'); } else console.log('Wrong Answer'); start(); } </script> https://code.sololearn.com/WTP9p3g5XnIZ/?ref=app
3 odpowiedzi
+ 4
Line 53: x = start();
+ 3
Your `start` function could be clearer this way:
function start(){
var fst = Math.floor(Math.random()*10);
document.getElementById("fst").innerHTML = fst;
var snd = Math.floor(Math.random()*10);
document.getElementById("snd").innerHTML = snd;
return fst + snd;
}
+ 1
Anna thankyou ma'am its working & please explain why we have to assign x to this calling function when all this start doing is just calling the function again