<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Ex 1</title>

    <script>
      function doMagic() {
        //function
        // Confirm with user if they want to see magic
        let confirmMagic = prompt("Do you really want to see a magic? (y/n)");

        // Check if user wants to see magic or not
        if (confirmMagic == "y") {
          document.getElementById("magic").innerHTML = "Magic happened";
        } else {
          document.getElementById("magic").innerHTML =
            "sorry, we realy wanted to show some magic";
        }

        // return statement is optional
      }
    </script>
  </head>
  <body>
    <button onclick="doMagic();">Do Magic</button>
    <p id="magic">Some magic is going to happen here</p>
  </body>
</html>

				
			

Some magic is going to happen here

Have a Project?

Let us connect Today!