36 lines
906 B
HTML
Executable file
36 lines
906 B
HTML
Executable file
<!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 l’usuari 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> |