HTML Compiler Online
Javascript Online Compiler
index.html
Change Theme
Compress code
Format code
Download Code
Clear Code
Copy Code!
RunĀ
ctrl+s or click
Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Javascript - Popup Prompt</title> </head> <body> <h2>Using "prompt()" method to create input box.</h2> <p>The value entered is returned as a string so if you want interger value than change string value to integer value.</p> <p id="sum"></p> <button onclick="sum()">Take Input And Add</button> <script> function sum() { var num1 = prompt("Enter 1st number:"); // taking input var num2 = prompt("Enter 2nd number:"); // taking input num1 = parseInt(num1); // String to integer num2 = parseInt(num2); var sum = num1 + num2; document.getElementById("sum").innerHTML = "Sum = " + sum; } </script> </body> </html>
RunĀ