JavaScript example #1
Fri Dec 18 2020 05:00:12 GMT+0000 (Coordinated Universal Time)
Saved by @Javkhlantugs ##javascript
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> <script> function MyExa1() { //display output var output1 = document.getElementById("output1"); output1.innerHTML = "Hello PD2<br /> Your age is 100<br />"; } function MyExa2() { //get inputs and display outputs var uName, uAge; //undefined uName = document.getElementById("uName").value; uAge = document.getElementById("uAge").value; document.getElementById("output2").innerHTML = ("Hello" + uName + "<br /> Your age is " + uAge + "< br />"); } function myExa3() { //get inputs, calculate and display result var num1, num2, total; num1 = document.getElementById("num1").value; num2 = document.getElementById("num2").value; total = Number(num1) + Number(num2); document.getElementById("output3").innerHTML = ("The total is" + total); // num1 = prompt("Enter the first number"); // num2 = prompt("Enter the second number"); // //total = (num1 - 0) + (num2 - 0); // total = Number(num1) + Number(num2); // documen.write("The total is " + total); } </script> </head> <body> <fieldset> <button onclick="MyExa1()"> Call the first function</button> <p id="output1"></p> </fieldset> <fieldset> <button onclick="MyExa2()"> Call the second function</button> <label>Enter Your Name</label> <input type="text" id="uName" /> <br /> <label>Enter Your Age</label> <input type="number" id="uAge" /> <br /> <p id="output2"></p> </fieldset> <fieldset> <button onclick="myExa3()"> Call the third function</button> <br/> <label>Enter the first number</label> <input type="number" id="num1" /> <br/> <label>Enter the second number</label> <input type="number" id="num2" /> <br /> <p id="output3"></p> </fieldset> </body> </html> <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> </head> <body> <script> //display output //document.write("Hello PD2<br /> Your age is 100<br />") //get inputs and display outputs //var uName, uAge; //undefined //uName = prompt("Enter your name"); //string //uAge = prompt("Enter your age", "18"); //string //document.write("Hello" + uName + "<br />Your age is " + uAge + "< br />"); //get inputs, calculate and display result var num1, num2, total; num1 = prompt("Enter the first number"); num2 = prompt("Enter the second number"); total = (num1 - 0) + (num2 - 0); //or total = Number(num1) + Number(num2); documen.write("The total is " + total); </script> </body> </html> <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> <script> function MyExa1() { //display output document.write("Hello PD2<br /> Your age is 100<br />") } function MyExa2() { //get inputs and display outputs var uName, uAge; //undefined uName = prompt("Enter your name"); //string uAge = prompt("Enter your age", "18"); //string document.write("Hello" + uName + " <br />Your age is " + uAge + "< br />"); } function myExa3() { //get inputs, calculate and display result var num1, num2, total; num1 = prompt("Enter the first number"); num2 = prompt("Enter the second number"); //total = (num1 - 0) + (num2 - 0); total = Number(num1) + Number(num2); document.write("The total is " + total); } </script> </head> <body> <fieldset> <button onclick="MyExa1()"> Call the first function</button> <p id="output1"></p> </fieldset> <fieldset> <button onclick="MyExa2()"> Call the second function</button> <label>Enter Your Name</label> <input type="text" id="uName" /> <br /> <label>Enter Your Age</label> <input type="number" id="uAge" /> <br/> <p id="output2"></p> </fieldset> <fieldset> <button onclick="myExa3()"> Call the third function</button> </fieldset> </body> </html>
Comments