Skip to content

Commit b2c94d4

Browse files
committed
feat: add compare numbers using the browser console
1 parent a1c9d05 commit b2c94d4

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,7 @@ Click to see the code in action 👉 [LIVE DEMO](https://armincano.github.io/ful
2626
- [Airline - Buy a flight](./m2-front-end-101/s5-s6-bootstrap/airline-promo-and-form/airline-promo-and-form.html)
2727
- [Form component](./m2-front-end-101/s5-s6-bootstrap/form/form.html)
2828
- [Cards and Navbar components](./m2-front-end-101/s5-s6-bootstrap/navbar-cards/navbar-cards.html)
29+
30+
### JavaScript
31+
32+
-[Compare numbers](./m2-front-end-101/s7-s8-javascript/browser-console/compare-numbers.html)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=
6+
, initial-scale=1.0">
7+
<title>Browser console - compare numbers</title>
8+
</head>
9+
<body>
10+
11+
<script src="./script.js"></script>
12+
</body>
13+
</html>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const getUserInput = (message) => {
2+
let userInput;
3+
do {
4+
userInput = prompt(message);
5+
if (userInput === null) {
6+
alert("Operación cancelada");
7+
return null;
8+
}
9+
} while (isNaN(parseInt(userInput)) || userInput.trim() === ""); //lo parseado no es un número o está vacío
10+
return parseInt(userInput);
11+
};
12+
13+
const compareNumbers = () => {
14+
alert("Vamos a comparar qué número es mayor");
15+
16+
const a = getUserInput("Introduce el primer número");
17+
if (a === null) return;
18+
const b = getUserInput("Introduce el segundo número");
19+
if (b === null) return;
20+
21+
if (a === b) {
22+
alert(`${a} y ${b} son iguales`);
23+
} else if (a > b) {
24+
alert(`${a} es mayor que ${b}`);
25+
} else {
26+
alert(`${b} es mayor que ${a}`);
27+
}
28+
};
29+
30+
compareNumbers();

0 commit comments

Comments
 (0)