+ 2
can I use "prompt" in the following code? đ
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="javascript" content="handling event"> <style> #demo { border-radius:18px; color:green; border-color:blue; background-color:white; } </style> <script> window.onload=function() { var btn=document.getElementById("demo"); btn.addEventListener("click", Sc00py); function Sc00py() { btn.removeEventListener("click", Sc00py); document.body.innerHTML=(Math.sqrt(81)); } } </script> </head> <body> <button id="demo">Start</button> </body> </html>
1 Answer
+ 2
Yes, you could do it as follows:
function Sc00py() {
btn.removeEventListener("click", Sc00py);
//prompt function
var mySquareVar = prompt("Please enter a number, I will display the square root");
document.body.innerHTML=Math.sqrt(mySquareVar);
}
And I recommend you to validate if the value prompted is a number.