Page 271 - Web Applications (803) Class 12
P. 271

<title>Number Sum</title>

                      </head>
                      <body>
                          <h1>Add Two Numbers</h1>

                          <script>
                              var num1 = parseInt(prompt(“Enter the first number:”));
                              var num2 = parseInt(prompt(“Enter the second number:”));

                              // Check if the input is valid
                              if (!isNaN(num1) && !isNaN(num2)) {

                                  var sum = num1 + num2;
                                  alert(“Sum of the numbers: “ + sum);
                              } else {
                                  alert(“Invalid input. Please enter valid numbers.”);

                              }
                          </script>

                      </body> </html>
                       Output:























                   4.   Write JavaScript code for changing background colour of the web page on the click of a button. Create multiple
                      such buttons for different colours.

                  Ans.  <html>

                      <head> <title>         EVENT HANDLING </title>
                      <script>
                      function changeColor(color) {
                       document.body.style.background = color;

                      }
                      </script></head>

                      <body bgcolor=”blue”>
                      <p> WELCOME </p>

                                                                                                    Practical Work   269
   266   267   268   269   270   271   272   273   274   275   276