-
Notifications
You must be signed in to change notification settings - Fork 228
Conditional operators: if, '?' #231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 27 commits
6941a56
e9b7747
c72776f
1c10a2b
643b511
26f6448
dfe7d40
7977b4a
e2bb1ec
0bb1510
adefcea
10bdedb
50ed670
fc95df9
d6686c0
96c3ae7
341830f
fbbb9c0
a29d26e
18cac2f
51c83f0
f3a2697
a589360
c477d72
1848326
a76a61c
0953da0
5f314c6
738f22f
ac725a5
49f1dfe
ffde1eb
38b09b4
36b9977
5c02c93
22388e4
438d1b9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
**Yes, it will.** | ||
|
||
Any string except an empty one (and `"0"` is not empty) becomes `true` in the logical context. | ||
Cualquier string excepto uno vacío (y `"0"` que no es vacío) se convierte en `true` en un contexto lógico. | ||
|
||
We can run and check: | ||
Podemos correr y revisar esto: | ||
EzequielCaste marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```js run | ||
if ("0") { | ||
alert( 'Hello' ); | ||
alert( 'Hola' ); | ||
} | ||
``` | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2,13 +2,12 @@ importance: 2 | |||||
|
||||||
--- | ||||||
|
||||||
# The name of JavaScript | ||||||
# El nombre de JavaScript | ||||||
|
||||||
Using the `if..else` construct, write the code which asks: 'What is the "official" name of JavaScript?' | ||||||
Usando el constructor `if..else`, escribe el código que pregunta: '¿Cuál es el nombre "oficial" de JavaScript?' | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
If the visitor enters "ECMAScript", then output "Right!", otherwise -- output: "Didn't know? ECMAScript!" | ||||||
Si el visitador escribe "ECMAScript", Entonces muestras "¡Correcto!", de lo contrario -- muestra: "¿No lo sabes? ¡ECMAScript!" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
 | ||||||
|
||||||
[demo src="ifelse_task2"] | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -4,12 +4,12 @@ importance: 2 | |||||
|
||||||
# Show the sign | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
Using `if..else`, write the code which gets a number via `prompt` and then shows in `alert`: | ||||||
Usando el constructor `if..else`, escribe un código que obtenga a través de un `prompt` un número y entonces muestre en un `alert`: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
- `1`, if the value is greater than zero, | ||||||
- `-1`, if less than zero, | ||||||
- `0`, if equals zero. | ||||||
- `1`, si el valor es mayor que cero, | ||||||
- `-1`, si es menor que cero, | ||||||
- `0`, si es igual a cero. | ||||||
|
||||||
In this task we assume that the input is always a number. | ||||||
En la tarea asumimos que siempre el usuario introduce un número. | ||||||
|
||||||
[demo src="if_sign"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
|
||
|
||
```js | ||
result = (a + b < 4) ? 'Below' : 'Over'; | ||
result = (a + b < 4) ? 'Debajo' : 'Encima'; | ||
``` | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
|
||
|
||
```js | ||
let message = (login == 'Employee') ? 'Hello' : | ||
(login == 'Director') ? 'Greetings' : | ||
(login == '') ? 'No login' : | ||
let message = (login == 'Empleado') ? 'Hola' : | ||
(login == 'Director') ? 'Felicidades' : | ||
(login == '') ? 'Sin sesión' : | ||
''; | ||
``` | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2,21 +2,21 @@ importance: 5 | |||||
|
||||||
--- | ||||||
|
||||||
# Rewrite 'if..else' into '?' | ||||||
# Reescriba el 'if..else' con '?' | ||||||
|
||||||
Rewrite `if..else` using multiple ternary operators `'?'`. | ||||||
Reescriba el `if..else` utilizando operadores ternarios múltiples`'?'`. | ||||||
|
||||||
For readability, it's recommended to split the code into multiple lines. | ||||||
Para legibilidad, es recomendad dividirlo en múltiples lineas de código. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
```js | ||||||
let message; | ||||||
|
||||||
if (login == 'Employee') { | ||||||
message = 'Hello'; | ||||||
if (login == 'Empleado') { | ||||||
message = 'Hola'; | ||||||
} else if (login == 'Director') { | ||||||
message = 'Greetings'; | ||||||
message = 'Felicidades'; | ||||||
} else if (login == '') { | ||||||
message = 'No login'; | ||||||
message = 'Sin sesión'; | ||||||
} else { | ||||||
message = ''; | ||||||
} | ||||||
|
Uh oh!
There was an error while loading. Please reload this page.