can I use "prompt" in the following code? 👇 | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 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 Réponse
+ 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