-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhtmlandjavascriptexercises.html
More file actions
50 lines (44 loc) · 1.98 KB
/
htmlandjavascriptexercises.html
File metadata and controls
50 lines (44 loc) · 1.98 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
40
41
42
43
44
45
46
47
48
49
50
<!DOCTYPE html>
<html>
<head>
<title>JavaScript</title>
<meta charset=""UTF-8" />
<script>
function somar() {
const n1 = document.getElementById('n1').value
const n2 = document.getElementById('n2').value
const soma = Number(n1) + Number(n2)
document.getElementById('resultado').innerHTML = "O resultado é: " + soma
}
function substrair() {
const n1 = document.getElementById('n1').value
const n2 = document.getElementById('n2').value
const substrair = Number(n1) - Number(n2)
document.getElementById('resultado').innerHTML = "O resultado é: " + substrair
}
function multiplicar() {
const n1 = document.getElementById('n1').value
const n2 = document.getElementById('n2').value
const multiplicar = Number(n1) * Number(n2)
document.getElementById('resultado').innerHTML = "O resultado é: " + multiplicar
}
function dividir() {
const n1 = document.getElementById('n1').value
const n2 = document.getElementById('n2').value
const dividir = Number(n1) / Number(n2)
document.getElementById('resultado').innerHTML = "O resultado é: " + dividir
}
</script>
</head>
<body>
<form action="">
N1: <input type="text" id="n1"/><br>
N2: <input type="text" id="n2"/><br>
<input type="button" value="Somar" onclick="somar()">
<input type="button" value="Substrair" onclick="substrair()">
<input type="button" value="Multiplicar" onclick="multiplicar()">
<input type="button" value="Dividir" onclick="dividir()">
<h1 id="resultado">O resultado é: </h1>
</form>
</body>
</html>