-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
65 lines (59 loc) · 2.94 KB
/
script.js
File metadata and controls
65 lines (59 loc) · 2.94 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Funções dos exercícios (mantidas, apenas com pequenos ajustes de exibição)
function calcExercicio1() {
const input = document.getElementById('num1');
let valor = parseInt(input.value, 10);
if (isNaN(valor)) {
document.getElementById('result1').innerHTML = '⚠️ Digite um número inteiro válido.';
return;
}
document.getElementById('result1').innerHTML =
`🔹 Antecessor: <strong>${valor - 1}</strong> 🔸 Sucessor: <strong>${valor + 1}</strong>`;
}
function calcExercicio2() {
const input = document.getElementById('num2');
let valor = parseFloat(input.value);
if (isNaN(valor)) {
document.getElementById('result2').innerHTML = '⚠️ Digite um número válido.';
return;
}
document.getElementById('result2').innerHTML =
`🔹 Dobro: <strong>${valor * 2}</strong> 🔸 Triplo: <strong>${valor * 3}</strong>`;
}
function calcExercicio3() {
const base = parseFloat(document.getElementById('base3').value);
const altura = parseFloat(document.getElementById('altura3').value);
if (isNaN(base) || isNaN(altura)) {
document.getElementById('result3').innerHTML = '⚠️ Preencha base e altura com números.';
return;
}
const area = base * altura;
document.getElementById('result3').innerHTML =
`📐 Área = <strong>${area.toFixed(2)}</strong> (unidades²)`;
}
function calcExercicio4() {
const idade = parseInt(document.getElementById('idade4').value, 10);
if (isNaN(idade) || idade < 0) {
document.getElementById('result4').innerHTML = '⚠️ Digite uma idade válida (≥ 0).';
return;
}
document.getElementById('result4').innerHTML =
`📅 <strong>${idade * 365}</strong> dias (considerando 365 dias/ano)`;
}
function calcExercicio5() {
const idade = parseInt(document.getElementById('idade5').value, 10);
if (isNaN(idade) || idade < 0) {
document.getElementById('result5').innerHTML = '⚠️ Digite uma idade válida.';
return;
}
const maior = idade >= 18 ? '✅ Maior de idade' : '🔴 Menor de idade';
document.getElementById('result5').innerHTML =
`🧑 ${idade} anos: <strong>${maior}</strong>`;
}
// Executa ao carregar a página para mostrar resultados iniciais
window.onload = function () {
calcExercicio1();
calcExercicio2();
calcExercicio3();
calcExercicio4();
calcExercicio5();
};