forked from Raul-Gamero/JavaScript-Basics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
39 lines (33 loc) · 1.11 KB
/
index.html
File metadata and controls
39 lines (33 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Greeting</title>
</head>
<body>
<p id="greeting"></p>
<script>
const name = prompt("what's your name?");
const paragraph = document.getElementById("greeting");
paragraph.textContent = "Welcome, " + name;
</script>
<input type="number" id="number1" placeholder="Enter first number" />
<input type="number" id="number2" placeholder="Enter second number" />
<br />
<button id="sumButton">Sum</button>
<p id="result">The result is</p>
<script>
console.log("Script loaded");
const number1 = document.getElementById("number1");
const number2 = document.getElementById("number2");
const button = document.getElementById("sumButton");
const resultParagraph = document.getElementById("result");
button.addEventListener("click", function () {
const a = Number(number1.value);
const b = Number(number2.value);
const result = a + b;
resultParagraph.textContent = "The result is " + result;
});
</script>
</body>
</html>