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

36 lines
906 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>
/* Demanar a lusuari 2 números i mostrar quin és el més proper a 100.*/
n1 = parseInt(prompt("Primer numero: "));
n2 = parseInt(prompt("Segundo numero: "));
console.log(n1+","+n2);
if (n1 < 100) d1 = 100 - n1;
else d1 = n1 - 100;
if (n2 < 100) d2 = 100 - n2;
else d2 = n2 - 100;
console.log(d1+","+d2);
if ( d1 > d2)
{
document.write(n2+ " es mas cercano a 100 que "+n1);
} else {
document.write(n1+ " es mas cercano a 100 que "+n2);
}
</script>
</body>
</html>