jda_m06/uf01/Exercicis UF1_1. Solucions-20211107/ex04_mitjana.html
2022-02-16 16:13:08 +01:00

35 lines
987 B
HTML
Executable file
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
/* Fes un programa que demani tres números a lusuari i mostri la mitjana, el major i el menor.*/
n1 = parseInt(prompt("Primer numero: "));
n2 = parseInt(prompt("Segundo numero: "));
n3 = parseInt(prompt("Tercer numero: "));
console.log(n1+","+n2+","+n3);
media = (n1 + n2 + n3) / 3;
mayor = n1;
if (n2 > mayor) mayor = n2;
if (n3 > mayor) mayor = n3;
menor = n1;
if (n2 < menor) menor = n2;
if (n3 < menor) menor = n3;
document.write("media = "+media);
document.write("<br>mayor = "+mayor);
document.write("<br>menor = "+menor);
</script>
</body>
</html>