- Notifications
You must be signed in to change notification settings - Fork230
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
6941a56e9b7747c72776f1c10a2b643b51126f6448dfe7d407977b4ae2bb1ec0bb1510adefcea10bdedb50ed670fc95df9d6686c096c3ae7341830ffbbb9c0a29d26e18cac2f51c83f0f3a2697a589360c477d721848326a76a61c0953da05f314c6738f22fac725a549f1dfeffde1eb38b09b436b99775c02c9322388e4438d1b9File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,11 @@ | ||
| **Sí lo hará.** | ||
| Cualquier stringexcepto uno vacío (y `"0"`que no es vacío) se convierte en`true`en un contexto lógico. | ||
| Podemos ejecutar y verificar: | ||
| ```js run | ||
| if ("0") { | ||
| alert( 'Hola' ); | ||
| } | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -2,13 +2,12 @@ importance: 5 | ||
| --- | ||
| # if (un stringcon cero) | ||
| Se mostrará el`alert`? | ||
| ```js | ||
| if ("0") { | ||
| alert( 'Hello' ); | ||
| } | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -2,13 +2,12 @@ importance: 2 | ||||||
| --- | ||||||
| #El nombre de JavaScript | ||||||
| Usando el constructor`if..else`, escribe el código que pregunta: '¿Cuál es el nombre "oficial" de JavaScript?' | ||||||
Contributor 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
| ||||||
| Si el visitador escribe "ECMAScript",Entonces muestras "¡Correcto!",de lo contrario--muestra: "¿No lo sabes? ¡ECMAScript!" | ||||||
Contributor 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 |
|---|---|---|
| @@ -6,7 +6,7 @@ | ||
| <script> | ||
| 'use strict'; | ||
| let value = prompt('Escribe un número', 0); | ||
| if (value > 0) { | ||
| alert(1); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| ```js run | ||
| let value = prompt('Escribe un número', 0); | ||
| if (value > 0) { | ||
| alert( 1 ); | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -4,12 +4,12 @@ importance: 2 | ||||||
| # Show the sign | ||||||
Contributor 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
| ||||||
| Usando el constructor`if..else`,escribe un código que obtenga através de un`prompt`un número y entonces muestre en un `alert`: | ||||||
Contributor 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`,si el valor es mayor que cero, | ||||||
| - `-1`,si es menor que cero, | ||||||
| - `0`,si es igual a cero. | ||||||
| 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) ? 'Debajo' : 'Encima'; | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| ```js | ||
| 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 | ||||||
| --- | ||||||
| #Reescriba el'if..else'con '?' | ||||||
| Reescriba el`if..else`utilizando operadores ternarios múltiples`'?'`. | ||||||
| Para legibilidad, es recomendad dividirlo en múltiples lineas de código. | ||||||
Contributor 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 == 'Empleado') { | ||||||
| message = 'Hola'; | ||||||
| } else if (login == 'Director') { | ||||||
| message = 'Felicidades'; | ||||||
| } else if (login == '') { | ||||||
| message = 'Sin sesión'; | ||||||
| } else { | ||||||
| message = ''; | ||||||
| } | ||||||
Uh oh!
There was an error while loading.Please reload this page.