Skip to content

Commit 2b924a7

Browse files
authored
Merge pull request #1 from Sjesc/logical-operators
Logical operators
2 parents 5b4d97a + 927cb20 commit 2b924a7

File tree

18 files changed

+211
-210
lines changed

18 files changed

+211
-210
lines changed

1-js/02-first-steps/11-logical-operators/1-alert-null-2-undefined/solution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
The answer is `2`, that's the first truthy value.
1+
La respuesta es `2`, ese es el primer valor verdadero.
22

33
```js run
44
alert( null || 2 || undefined );

1-js/02-first-steps/11-logical-operators/1-alert-null-2-undefined/task.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ importance: 5
22

33
---
44

5-
# What's the result of OR?
5+
# ¿Cuál es el resultado de OR?
66

7-
What is the code below going to output?
7+
¿Cuál será la salida del siguiente código?
88

99
```js
1010
alert( null || 2 || undefined );
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
The answer: first `1`, then `2`.
1+
La repuesta: primero `1`, después `2`.
22

33
```js run
44
alert( alert(1) || 2 || alert(3) );
55
```
66

7-
The call to `alert` does not return a value. Or, in other words, it returns `undefined`.
7+
La llamada a `alert` no retorna un valor. O, en otras palabras, retorna `undefined`.
88

9-
1. The first OR `||` evaluates it's left operand `alert(1)`. That shows the first message with `1`.
10-
2. The `alert` returns `undefined`, so OR goes on to the second operand searching for a truthy value.
11-
3. The second operand `2` is truthy, so the execution is halted, `2` is returned and then shown by the outer alert.
9+
1. El primer OR `||` evalua el operando de la izquierda `alert(1)`. Eso muestra el primer mensaje con `1`.
10+
2. El `alert` retorna `undefined`, por lo que OR se dirige al segundo operando buscando un valor verdadero.
11+
3. El segundo operando `2` es un valor verdadero, por lo que se detiene la ejecución, se retorna `2` y es mostrado por el alert exterior.
1212

13-
There will be no `3`, because the evaluation does not reach `alert(3)`.
13+
No habrá `3` debido a que la evaluación no alcanza a `alert(3)`.

1-js/02-first-steps/11-logical-operators/2-alert-or/task.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ importance: 3
22

33
---
44

5-
# What's the result of OR'ed alerts?
5+
# ¿Cuál es el resultado de las alertas aplicadas al operador OR?
66

7-
What will the code below output?
7+
¿Cuál será la salida del siguiente código?
88

99
```js
1010
alert( alert(1) || 2 || alert(3) );

1-js/02-first-steps/11-logical-operators/3-alert-1-null-2/solution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
The answer: `null`, because it's the first falsy value from the list.
1+
La respuesta: `null`, porque es el primer valor falso de la lista.
22

33
```js run
44
alert( 1 && null && 2 );

1-js/02-first-steps/11-logical-operators/3-alert-1-null-2/task.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ importance: 5
22

33
---
44

5-
# What is the result of AND?
5+
# ¿Cuál es el resultado de AND?
66

7-
What is this code going to show?
7+
¿Cuál será la salida del siguiente código?
88

99
```js
1010
alert( 1 && null && 2 );
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
The answer: `1`, and then `undefined`.
1+
La respuesta: `1` y después `undefined`.
22

33
```js run
44
alert( alert(1) && alert(2) );
55
```
66

7-
The call to `alert` returns `undefined` (it just shows a message, so there's no meaningful return).
8-
9-
Because of that, `&&` evaluates the left operand (outputs `1`), and immediately stops, because `undefined` is a falsy value. And `&&` looks for a falsy value and returns it, so it's done.
7+
La llamada a `alert` retorna `undefined` (solo muestra un mensaje, así que no hay un valor que retornar relevante)
108

9+
Debido a ello, `&&` evalua el operando de la izquierda (imprime `1`) e inmediatamente se detiene porque `undefined` es un valor falso. Como `&&` busca un valor falso y lo retorna, terminamos.

1-js/02-first-steps/11-logical-operators/4-alert-and/task.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ importance: 3
22

33
---
44

5-
# What is the result of AND'ed alerts?
5+
# ¿Cuál es el resultado de las alertas aplicadas al operador AND?
66

7-
What will this code show?
7+
¿Cuál será la salida del siguiente código?
88

99
```js
1010
alert( alert(1) && alert(2) );
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
The answer: `3`.
1+
La respuesta: `3`.
22

33
```js run
44
alert( null || 2 && 3 || 4 );
55
```
66

7-
The precedence of AND `&&` is higher than `||`, so it executes first.
7+
La precedencia de AND `&&` es mayor que la de `||`, así que se ejecuta primero.
88

9-
The result of `2 && 3 = 3`, so the expression becomes:
9+
El resultado de `2 && 3 = 3`, por lo que la expresión se convierte en:
1010

1111
```
1212
null || 3 || 4
1313
```
1414

15-
Now the result is the first truthy value: `3`.
15+
Ahora el resultado será el primer valor verdadero: `3`.
1616

1-js/02-first-steps/11-logical-operators/5-alert-and-or/task.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ importance: 5
22

33
---
44

5-
# The result of OR AND OR
5+
# El resultado de OR AND OR
66

7-
What will the result be?
7+
¿Cuál será el resultado?
88

99
```js
1010
alert( null || 2 && 3 || 4 );

1-js/02-first-steps/11-logical-operators/6-check-if-in-range/task.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ importance: 3
22

33
---
44

5-
# Check the range between
5+
# Comprueba el rango por dentro
66

7-
Write an "if" condition to check that `age` is between `14` and `90` inclusively.
7+
Escribe una condición "if" para comprobar que `age`(edad) está entre `14` y `90` inclusivamente.
88

9-
"Inclusively" means that `age` can reach the edges `14` or `90`.
9+
"Inclusivamente" significa que `age` puede llegar a ser uno de los extremos, `14` o `90`.

1-js/02-first-steps/11-logical-operators/7-check-if-out-range/solution.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
The first variant:
1+
La primer variante:
22

33
```js
44
if (!(age >= 14 && age <= 90))
55
```
66

7-
The second variant:
7+
La segunda variante:
88

99
```js
1010
if (age < 14 || age > 90)

1-js/02-first-steps/11-logical-operators/7-check-if-out-range/task.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ importance: 3
22

33
---
44

5-
# Check the range outside
5+
# Comprueba el rango por fuera
66

7-
Write an `if` condition to check that `age` is NOT between 14 and 90 inclusively.
7+
Escribe una condición `if` para comprobar que `age` NO está entre 14 y 90 inclusivemente.
88

9-
Create two variants: the first one using NOT `!`, the second one -- without it.
9+
Crea dos variantes: la primera usando NOT `!`, y la segunda -- sin usarlo.
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
The answer: the first and the third will execute.
1+
La respuesta: el primero y el tercero serán ejecutados.
22

3-
Details:
3+
Detalles:
44

55
```js run
6-
// Runs.
7-
// The result of -1 || 0 = -1, truthy
8-
if (-1 || 0) alert( 'first' );
6+
// Corre.
7+
// El resultado de -1 || 0 = -1, valor verdadero
8+
if (-1 || 0) alert( "primero" );
99

10-
// Doesn't run
11-
// -1 && 0 = 0, falsy
12-
if (-1 && 0) alert( 'second' );
10+
// No corre.
11+
// -1 && 0 = 0, valor falso
12+
if (-1 && 0) alert( "segundo" );
1313

14-
// Executes
15-
// Operator && has a higher precedence than ||
16-
// so -1 && 1 executes first, giving us the chain:
14+
// Se ejecuta
15+
// El operador && tiene mayor precedencia que ||
16+
// Así que -1 && 1 se ejecuta primero, dándonos la cadena:
1717
// null || -1 && 1 -> null || 1 -> 1
18-
if (null || -1 && 1) alert( 'third' );
18+
if (null || -1 && 1) alert( "tercero" );
1919
```
2020

1-js/02-first-steps/11-logical-operators/8-if-question/task.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ importance: 5
22

33
---
44

5-
# A question about "if"
5+
# Un pregunta acerca de "if"
66

7-
Which of these `alert`s are going to execute?
7+
¿Cuáles de estos `alert`s va a ejecutarse?
88

9-
What will the results of the expressions be inside `if(...)`?
9+
¿Cuáles serán los resultados de las expresiones dentro de `if(...)`?
1010

1111
```js
12-
if (-1 || 0) alert( 'first' );
13-
if (-1 && 0) alert( 'second' );
14-
if (null || -1 && 1) alert( 'third' );
12+
if (-1 || 0) alert( "primero" );
13+
if (-1 && 0) alert( "segundo" );
14+
if (null || -1 && 1) alert( "tercero" );
1515
```
1616

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11

22

33
```js run demo
4-
let userName = prompt("Who's there?", '');
4+
let userName = prompt("Quién está ahí?", "");
55

6-
if (userName == 'Admin') {
6+
if (userName == "Admin") {
7+
8+
let pass = prompt("Contraseña?", "");
79

8-
let pass = prompt('Password?', '');
9-
10-
if (pass == 'TheMaster') {
11-
alert( 'Welcome!' );
12-
} else if (pass == '' || pass == null) {
13-
alert( 'Canceled.' );
14-
} else {
15-
alert( 'Wrong password' );
16-
}
17-
18-
} else if (userName == '' || userName == null) {
19-
alert( 'Canceled' );
10+
if (pass == "TheMaster") {
11+
alert( "Bienvenido!" );
12+
} else if (pass == "" || pass == null) {
13+
alert( "Cancelado." );
14+
} else {
15+
alert( "Contraseña incorrecta" );
16+
}
17+
18+
} else if (userName == "" || userName == null) {
19+
alert( "Canceledo" );
2020
} else {
21-
alert( "I don't know you" );
21+
alert( "No te conozco" );
2222
}
2323
```
2424

25-
Note the vertical indents inside the `if` blocks. They are technically not required, but make the code more readable.
25+
Nota las sangrías verticales dentro de los bloques `if`. Técnicamente no son necesarias, pero facilitan la lectura del código.

1-js/02-first-steps/11-logical-operators/9-check-login/task.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,24 @@ importance: 3
22

33
---
44

5-
# Check the login
5+
# Comprueba el inicio de sesión
66

7-
Write the code which asks for a login with `prompt`.
7+
Escribe un código que pregunte por el inicio de sesión con `propmt`.
88

9-
If the visitor enters `"Admin"`, then `prompt` for a password, if the input is an empty line or `key:Esc` -- show "Canceled.", if it's another string -- then show "I don't know you".
9+
Si el visitante ingresa `"Admin"`, entonces `prompt`(pregunta) por una contraseña, si la entrada es una linea vacía o `key:Esc` -- muestra "Cancelado.", si es otra cadena de texto -- entonces muestra "No te conozco".
1010

11-
The password is checked as follows:
11+
La contraseña se comprueba de la siguiente manera:
1212

13-
- If it equals "TheMaster", then show "Welcome!",
14-
- Another string -- show "Wrong password",
15-
- For an empty string or cancelled input, show "Canceled."
13+
- Si es igual a "TheMaster", entonces muestra "Bienvenido!",
14+
- Si es otra cadena de texto -- muetra "Contraseña incorrecta",
15+
- Para una cadena de texto vacía o una entrada cancelada, muestra "Cancelado."
1616

17-
The schema:
17+
El esquema:
1818

1919
![](ifelse_task.png)
2020

21-
Please use nested `if` blocks. Mind the overall readability of the code.
21+
Por favor usa bloques anidados de `if`. Piensa en la legibilidad general del código.
2222

23-
Hint: passing an empty input to a prompt returns an empty string `''`. Pressing `key:ESC` during a prompt returns `null`.
23+
Pista: si se le pasa una entrada vacía a un prompt, retorna una cadena de texto vacía `''`. Presionando `key:ESC` durante un prompt retorna `null`.
2424

2525
[demo]

0 commit comments

Comments
 (0)