-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Cadenas en Javascript | ||
|
||
Para este ejercicio solo necesitas modificar el archivo `js/main.js`. Si abres el `index.html`en el navegador, puedes dar click en el botón para verificar el resultado del ejercicio ahi mismo. | ||
|
||
## Tareas | ||
|
||
1. Crear una variable llamada `myString` cuyo valor sea "Salem es el mejor gato del mundo." (sin comillas). | ||
2. Crear una variable llamada `stringLength` cuyo valor sea el total de caracteres en la cadena `myString`. | ||
3. Crear una variable llamada `catIsAtPosition` cuyo valor sea la posición de la palabra "gato" en la cadena `myString`. | ||
4. Crear una variable llamada `myNewString` cuyo valor sea el mismo que `myString`, pero con la palabra "gato" reemplazada por "michi". | ||
|
||
Documentación de cadenas: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>JS Strings</title> | ||
</head> | ||
<body> | ||
<button id="btn">Verificar</button> | ||
<script src="js/main.js"></script> | ||
<script> | ||
let task = 1; | ||
const check = (value, name, expected) => { | ||
if (typeof value === "undefined" || value !== expected) { | ||
throw new Error( | ||
`Tarea ${task} incompleta: El valor de "${name}" es incorrecto.`, | ||
); | ||
} | ||
task++; | ||
}; | ||
document.getElementById("btn").addEventListener("click", () => { | ||
try { | ||
check( | ||
myString, | ||
"myString", | ||
"Salem es el mejor gato del mundo.", | ||
); | ||
check(stringLength, "stringLength", 33); | ||
check(catIsAtPosition, "catIsAtPosition", 18); | ||
check( | ||
myNewString, | ||
"myNewString", | ||
"Salem es el mejor michi del mundo.", | ||
); | ||
|
||
alert("Todo correcto!"); | ||
} catch ({ message }) { | ||
if (message.indexOf("is not defined") !== -1) { | ||
const [varName] = message.split(" ", 1); | ||
alert( | ||
`Tarea ${task} incompleta: Variable "${varName}" no está definida.`, | ||
); | ||
} else { | ||
alert(message); | ||
} | ||
} | ||
task = 1; | ||
}); | ||
</script> | ||
</body> | ||
</html> |
Empty file.