Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function sum() {
- var y = document.getElementById("txt1").value;
- var z = document.getElementById("txt2").value;
- var x = Number(y) + Number(z);
- document.getElementById("demo").innerHTML = "[" + y + " ] + [ " + z + " ] = " + x;
- }
- <!doctype html>
- <html lang="en">
- <head>
- <title>Calculator</title>
- <meta charset="utf-8">
- <style>
- html, body {
- height: 100%;
- }
- body {
- display: flex;
- align-items: center;
- justify-content: center;
- flex-direction: column;
- margin: 0;
- }
- </style>
- <script src="index2.js"></script>
- </head>
- <body>
- <input type="number" id="txt1">
- <input type="number" id="txt2">
- <button onclick="sum()">Calculate</button>
- <p id="demo"></p>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement