-
Notifications
You must be signed in to change notification settings - Fork 0
/
Média Aritmética.html
36 lines (32 loc) · 1.47 KB
/
Média Aritmética.html
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
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Média Aritmética</title>
</head>
<body>
<h1>Calcularemos a Média Aritmética!</h1>
<input type="number" id="valor1" placeholder="Valor 1">
<input type="number" id="valor2" placeholder="Valor 2">
<input type="number" id="valor3" placeholder="Valor 3">
<input type="number" id="valor4" placeholder="Valor 4">
<input type="number" id="valor5" placeholder="Valor 5">
<input type="number" id="valor6" placeholder="Valor 6">
<button onclick="calcularMedia()">Vamos calcular?</button>
<p id="resultado"></p>
<script>
function calcularMedia() {
const valores = [
parseFloat(document.getElementById('valor1').value),
parseFloat(document.getElementById('valor2').value),
parseFloat(document.getElementById('valor3').value),
parseFloat(document.getElementById('valor4').value),
parseFloat(document.getElementById('valor5').value),
parseFloat(document.getElementById('valor6').value)
];
const soma = valores.reduce((acc, val) => acc + val, 0);
const media = soma / valores.length;
document.getElementById('resultado').textContent = `A média aritmética é 🤓: ${media.toFixed(2)}`;
}
</script>