+ 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>

10th Oct 2016, 5:07 PM
Li KyĂŒi Ng'bawi Awm
Li KyĂŒi Ng'bawi Awm - avatar
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.
10th Oct 2016, 9:24 PM
AdriĂĄn Pizarro
AdriĂĄn Pizarro - avatar