let ans=document.querySelector("p")
let text;
text=Math.floor(Math.random()*100+1);
flag=true;
while(flag===true){
let guessed=parseInt(prompt("Guess the number?"));
if (guessed===text){
ans.textContent="Congratulations! U guessed it right!";
flag=false;
}
else if (guessed>text){
ans.textContent="Guess lower!";
}
else if (guessed<text){
ans.textContent="Guess higher!";
}
}
How do i prompt the user using prompt() function after the HTML has completely loaded?
The above code will not load complete html and prompts the user immediately as you reload the page.