chore(i18n,curriculum): update translations
This commit is contained in:
committed by
Mrugesh Mohapatra
parent
e139fbcf13
commit
c1fb339bbc
@ -18,9 +18,9 @@ Los índices de los arreglos se escriben en la misma notación de corchetes que
|
||||
**Ejemplo**
|
||||
|
||||
```js
|
||||
var array = [50,60,70];
|
||||
const array = [50, 60, 70];
|
||||
array[0];
|
||||
var data = array[1];
|
||||
const data = array[1];
|
||||
```
|
||||
|
||||
`array[0]` ahora es `50` y `data` tiene el valor `60`.
|
||||
@ -76,7 +76,7 @@ if(typeof myArray !== "undefined" && typeof myData !== "undefined"){(function(y,
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
var myArray = [50,60,70];
|
||||
const myArray = [50, 60, 70];
|
||||
|
||||
|
||||
```
|
||||
@ -84,6 +84,6 @@ var myArray = [50,60,70];
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myArray = [50,60,70];
|
||||
var myData = myArray[0];
|
||||
const myArray = [50, 60, 70];
|
||||
const myData = myArray[0];
|
||||
```
|
||||
|
@ -14,12 +14,13 @@ Se puede pensar que un arreglo <dfn>multidimensional</dfn> es como un *arreglo d
|
||||
**Ejemplo**
|
||||
|
||||
```js
|
||||
var arr = [
|
||||
[1,2,3],
|
||||
[4,5,6],
|
||||
[7,8,9],
|
||||
[[10,11,12], 13, 14]
|
||||
const arr = [
|
||||
[1, 2, 3],
|
||||
[4, 5, 6],
|
||||
[7, 8, 9],
|
||||
[[10, 11, 12], 13, 14]
|
||||
];
|
||||
|
||||
arr[3];
|
||||
arr[3][0];
|
||||
arr[3][0][1];
|
||||
@ -58,14 +59,19 @@ if(typeof myArray !== "undefined"){(function(){return "myData: " + myData + " my
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
var myArray = [[1,2,3], [4,5,6], [7,8,9], [[10,11,12], 13, 14]];
|
||||
const myArray = [
|
||||
[1, 2, 3],
|
||||
[4, 5, 6],
|
||||
[7, 8, 9],
|
||||
[[10, 11, 12], 13, 14],
|
||||
];
|
||||
|
||||
var myData = myArray[0][0];
|
||||
const myData = myArray[0][0];
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myArray = [[1,2,3],[4,5,6], [7,8,9], [[10,11,12], 13, 14]];
|
||||
var myData = myArray[2][1];
|
||||
const myArray = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [[10, 11, 12], 13, 14]];
|
||||
const myData = myArray[2][1];
|
||||
```
|
||||
|
@ -14,7 +14,7 @@ Como hemos visto en ejemplos anteriores, los objetos pueden contener tanto objet
|
||||
En el siguiente ejemplo, vemos cómo se accede a un arreglo anidado:
|
||||
|
||||
```js
|
||||
var ourPets = [
|
||||
const ourPets = [
|
||||
{
|
||||
animalType: "cat",
|
||||
names: [
|
||||
@ -32,6 +32,7 @@ var ourPets = [
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
ourPets[0].names[1];
|
||||
ourPets[1].names[0];
|
||||
```
|
||||
@ -72,7 +73,7 @@ assert(/=\s*myPlants\[1\].list\[1\]/.test(code));
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
var myPlants = [
|
||||
const myPlants = [
|
||||
{
|
||||
type: "flowers",
|
||||
list: [
|
||||
@ -91,13 +92,13 @@ var myPlants = [
|
||||
}
|
||||
];
|
||||
|
||||
var secondTree = "";
|
||||
const secondTree = "";
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myPlants = [
|
||||
const myPlants = [
|
||||
{
|
||||
type: "flowers",
|
||||
list: [
|
||||
@ -116,5 +117,5 @@ var myPlants = [
|
||||
}
|
||||
];
|
||||
|
||||
var secondTree = myPlants[1].list[1];
|
||||
const secondTree = myPlants[1].list[1];
|
||||
```
|
||||
|
@ -14,7 +14,7 @@ Se puede acceder a las sub propiedades de objetos encadenando la notación de pu
|
||||
Aquí hay un objeto anidado:
|
||||
|
||||
```js
|
||||
var ourStorage = {
|
||||
const ourStorage = {
|
||||
"desk": {
|
||||
"drawer": "stapler"
|
||||
},
|
||||
@ -26,6 +26,7 @@ var ourStorage = {
|
||||
"bottom drawer": "soda"
|
||||
}
|
||||
};
|
||||
|
||||
ourStorage.cabinet["top drawer"].folder2;
|
||||
ourStorage.desk.drawer;
|
||||
```
|
||||
@ -66,7 +67,7 @@ assert(/=\s*myStorage\.car\.inside\[\s*("|')glove box\1\s*\]/g.test(code));
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
var myStorage = {
|
||||
const myStorage = {
|
||||
"car": {
|
||||
"inside": {
|
||||
"glove box": "maps",
|
||||
@ -78,13 +79,13 @@ var myStorage = {
|
||||
}
|
||||
};
|
||||
|
||||
var gloveBoxContents = undefined;
|
||||
const gloveBoxContents = undefined;
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myStorage = {
|
||||
const myStorage = {
|
||||
"car":{
|
||||
"inside":{
|
||||
"glove box":"maps",
|
||||
@ -95,5 +96,5 @@ var myStorage = {
|
||||
}
|
||||
}
|
||||
};
|
||||
var gloveBoxContents = myStorage.car.inside["glove box"];
|
||||
const gloveBoxContents = myStorage.car.inside["glove box"];
|
||||
```
|
||||
|
@ -16,11 +16,12 @@ Sin embargo, también puedes utilizar la notación de corchetes en las propiedad
|
||||
Aquí hay un ejemplo de cómo usar la notación de corchetes para leer la propiedad de un objeto:
|
||||
|
||||
```js
|
||||
var myObj = {
|
||||
const myObj = {
|
||||
"Space Name": "Kirk",
|
||||
"More Space": "Spock",
|
||||
"NoSpace": "USS Enterprise"
|
||||
};
|
||||
|
||||
myObj["Space Name"];
|
||||
myObj['More Space'];
|
||||
myObj["NoSpace"];
|
||||
@ -78,26 +79,25 @@ assert(code.match(/testObj\s*?\[('|")[^'"]+\1\]/g).length > 1);
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var testObj = {
|
||||
const testObj = {
|
||||
"an entree": "hamburger",
|
||||
"my side": "veggies",
|
||||
"the drink": "water"
|
||||
};
|
||||
|
||||
// Only change code below this line
|
||||
|
||||
var entreeValue = testObj; // Change this line
|
||||
var drinkValue = testObj; // Change this line
|
||||
const entreeValue = testObj; // Change this line
|
||||
const drinkValue = testObj; // Change this line
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var testObj = {
|
||||
const testObj = {
|
||||
"an entree": "hamburger",
|
||||
"my side": "veggies",
|
||||
"the drink": "water"
|
||||
};
|
||||
var entreeValue = testObj["an entree"];
|
||||
var drinkValue = testObj['the drink'];
|
||||
const entreeValue = testObj["an entree"];
|
||||
const drinkValue = testObj['the drink'];
|
||||
```
|
||||
|
@ -16,15 +16,17 @@ La notación de puntos es lo que se usa cuando conoces el nombre de la propiedad
|
||||
Aquí hay un ejemplo de cómo usar la notación de puntos (`.`) para leer la propiedad de un objeto:
|
||||
|
||||
```js
|
||||
var myObj = {
|
||||
const myObj = {
|
||||
prop1: "val1",
|
||||
prop2: "val2"
|
||||
};
|
||||
var prop1val = myObj.prop1;
|
||||
var prop2val = myObj.prop2;
|
||||
|
||||
const prop1val = myObj.prop1;
|
||||
const prop2val = myObj.prop2;
|
||||
```
|
||||
|
||||
`prop1val` tendrá una cadena con valor `val1` y `prop2val` tendrá una cadena con valor `val2`.
|
||||
|
||||
# --instructions--
|
||||
|
||||
Lee los valores de las propiedades de `testObj` utilizando la notación de puntos. Asigna la variable `hatValue` igual a la propiedad `hat` del objeto y asigna la variable `shirtValue` igual a la propiedad `shirt` del objeto.
|
||||
@ -73,27 +75,26 @@ assert(code.match(/testObj\.\w+/g).length > 1);
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var testObj = {
|
||||
const testObj = {
|
||||
"hat": "ballcap",
|
||||
"shirt": "jersey",
|
||||
"shoes": "cleats"
|
||||
};
|
||||
|
||||
// Only change code below this line
|
||||
|
||||
var hatValue = testObj; // Change this line
|
||||
var shirtValue = testObj; // Change this line
|
||||
const hatValue = testObj; // Change this line
|
||||
const shirtValue = testObj; // Change this line
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var testObj = {
|
||||
const testObj = {
|
||||
"hat": "ballcap",
|
||||
"shirt": "jersey",
|
||||
"shoes": "cleats"
|
||||
};
|
||||
|
||||
var hatValue = testObj.hat;
|
||||
var shirtValue = testObj.shirt;
|
||||
const hatValue = testObj.hat;
|
||||
const shirtValue = testObj.shirt;
|
||||
```
|
||||
|
@ -14,11 +14,14 @@ Otro uso de la notación de corchetes en objetos es acceder a una propiedad que
|
||||
Aquí hay un ejemplo del uso de una variable para acceder a una propiedad:
|
||||
|
||||
```js
|
||||
var dogs = {
|
||||
Fido: "Mutt", Hunter: "Doberman", Snoopie: "Beagle"
|
||||
const dogs = {
|
||||
Fido: "Mutt",
|
||||
Hunter: "Doberman",
|
||||
Snoopie: "Beagle"
|
||||
};
|
||||
var myDog = "Hunter";
|
||||
var myBreed = dogs[myDog];
|
||||
|
||||
const myDog = "Hunter";
|
||||
const myBreed = dogs[myDog];
|
||||
console.log(myBreed);
|
||||
```
|
||||
|
||||
@ -27,14 +30,16 @@ La cadena `Doberman` se mostrará en la consola.
|
||||
Otra forma de usar este concepto es cuando el nombre de la propiedad se recoge dinámicamente durante la ejecución del programa, de la siguiente manera:
|
||||
|
||||
```js
|
||||
var someObj = {
|
||||
const someObj = {
|
||||
propName: "John"
|
||||
};
|
||||
|
||||
function propPrefix(str) {
|
||||
var s = "prop";
|
||||
const s = "prop";
|
||||
return s + str;
|
||||
}
|
||||
var someProp = propPrefix("Name");
|
||||
|
||||
const someProp = propPrefix("Name");
|
||||
console.log(someObj[someProp]);
|
||||
```
|
||||
|
||||
@ -96,26 +101,25 @@ if(typeof player !== "undefined"){(function(v){return v;})(player);}
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var testObj = {
|
||||
const testObj = {
|
||||
12: "Namath",
|
||||
16: "Montana",
|
||||
19: "Unitas"
|
||||
};
|
||||
|
||||
// Only change code below this line
|
||||
|
||||
var playerNumber; // Change this line
|
||||
var player = testObj; // Change this line
|
||||
const playerNumber = 42; // Change this line
|
||||
const player = testObj; // Change this line
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var testObj = {
|
||||
const testObj = {
|
||||
12: "Namath",
|
||||
16: "Montana",
|
||||
19: "Unitas"
|
||||
};
|
||||
var playerNumber = 16;
|
||||
var player = testObj[playerNumber];
|
||||
const playerNumber = 16;
|
||||
const player = testObj[playerNumber];
|
||||
```
|
||||
|
@ -28,7 +28,7 @@ Ahora cuando evaluemos `ourDog.bark`, obtendremos su ladrido, `bow-wow`.
|
||||
Por ejemplo:
|
||||
|
||||
```js
|
||||
var ourDog = {
|
||||
const ourDog = {
|
||||
"name": "Camper",
|
||||
"legs": 4,
|
||||
"tails": 1,
|
||||
@ -67,7 +67,7 @@ assert(!/bark[^\n]:/.test(code));
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
var myDog = {
|
||||
const myDog = {
|
||||
"name": "Happy Coder",
|
||||
"legs": 4,
|
||||
"tails": 1,
|
||||
@ -80,7 +80,7 @@ var myDog = {
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myDog = {
|
||||
const myDog = {
|
||||
"name": "Happy Coder",
|
||||
"legs": 4,
|
||||
"tails": 1,
|
||||
|
@ -18,7 +18,7 @@ JavaScript utiliza el símbolo `+` como un operador de adición cuando se coloca
|
||||
**Ejemplo:**
|
||||
|
||||
```js
|
||||
myVar = 5 + 10;
|
||||
const myVar = 5 + 10;
|
||||
```
|
||||
|
||||
`myVar` ahora tiene el valor `15`.
|
||||
@ -52,11 +52,11 @@ assert(/\+/.test(code));
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
var sum = 10 + 0;
|
||||
const sum = 10 + 0;
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var sum = 10 + 10;
|
||||
const sum = 10 + 10;
|
||||
```
|
||||
|
@ -92,7 +92,7 @@ assert(code.match(/break/g).length > 2);
|
||||
|
||||
```js
|
||||
function switchOfStuff(val) {
|
||||
var answer = "";
|
||||
let answer = "";
|
||||
// Only change code below this line
|
||||
|
||||
|
||||
@ -108,7 +108,7 @@ switchOfStuff(1);
|
||||
|
||||
```js
|
||||
function switchOfStuff(val) {
|
||||
var answer = "";
|
||||
let answer = "";
|
||||
|
||||
switch(val) {
|
||||
case "a":
|
||||
|
@ -14,8 +14,8 @@ Al igual que podemos construir una cadena sobre múltiples líneas a partir de l
|
||||
Ejemplo:
|
||||
|
||||
```js
|
||||
var anAdjective = "awesome!";
|
||||
var ourStr = "freeCodeCamp is ";
|
||||
const anAdjective = "awesome!";
|
||||
let ourStr = "freeCodeCamp is ";
|
||||
ourStr += anAdjective;
|
||||
```
|
||||
|
||||
@ -64,15 +64,14 @@ assert(code.match(/myStr\s*\+=\s*someAdjective\s*/).length > 0);
|
||||
|
||||
```js
|
||||
// Change code below this line
|
||||
|
||||
var someAdjective;
|
||||
var myStr = "Learning to code is ";
|
||||
const someAdjective = "";
|
||||
let myStr = "Learning to code is ";
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var someAdjective = "neat";
|
||||
var myStr = "Learning to code is ";
|
||||
const someAdjective = "neat";
|
||||
let myStr = "Learning to code is ";
|
||||
myStr += someAdjective;
|
||||
```
|
||||
|
@ -18,7 +18,7 @@ Los objetos son útiles para almacenar datos de forma estructurada y pueden repr
|
||||
Por ejemplo, aquí hay un objeto de gato:
|
||||
|
||||
```js
|
||||
var cat = {
|
||||
const cat = {
|
||||
"name": "Whiskers",
|
||||
"legs": 4,
|
||||
"tails": 1,
|
||||
@ -29,7 +29,7 @@ var cat = {
|
||||
En este ejemplo, todas las propiedades se almacenan como cadenas, como `name`, `legs` y `tails`. Sin embargo, también puedes utilizar números como propiedades. Incluso puedes omitir las comillas para las propiedades de cadenas de una sola palabra, de la siguiente manera:
|
||||
|
||||
```js
|
||||
var anotherObject = {
|
||||
const anotherObject = {
|
||||
make: "Ford",
|
||||
5: "five",
|
||||
"model": "focus"
|
||||
@ -139,18 +139,18 @@ assert(
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
var myDog = {
|
||||
// Only change code below this line
|
||||
const myDog = {
|
||||
// Only change code below this line
|
||||
|
||||
|
||||
// Only change code above this line
|
||||
// Only change code above this line
|
||||
};
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myDog = {
|
||||
const myDog = {
|
||||
"name": "Camper",
|
||||
"legs": 4,
|
||||
"tails": 1,
|
||||
|
@ -16,7 +16,7 @@ El operador más básico es el de igualdad `==`. El operador de igualdad compara
|
||||
```js
|
||||
function equalityTest(myVal) {
|
||||
if (myVal == 10) {
|
||||
return "Equal";
|
||||
return "Equal";
|
||||
}
|
||||
return "Not Equal";
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ para sumar `5` a `myVar`. Dado que se trata de un patrón tan común, hay operad
|
||||
Uno de estos operadores es el operador `+=`.
|
||||
|
||||
```js
|
||||
var myVar = 1;
|
||||
let myVar = 1;
|
||||
myVar += 5;
|
||||
console.log(myVar);
|
||||
```
|
||||
@ -61,9 +61,9 @@ No debes modificar el código por encima del comentario especificado.
|
||||
|
||||
```js
|
||||
assert(
|
||||
/var a = 3;/.test(code) &&
|
||||
/var b = 17;/.test(code) &&
|
||||
/var c = 12;/.test(code)
|
||||
/let a = 3;/.test(code) &&
|
||||
/let b = 17;/.test(code) &&
|
||||
/let c = 12;/.test(code)
|
||||
);
|
||||
```
|
||||
|
||||
@ -78,9 +78,9 @@ assert(
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
var a = 3;
|
||||
var b = 17;
|
||||
var c = 12;
|
||||
let a = 3;
|
||||
let b = 17;
|
||||
let c = 12;
|
||||
|
||||
// Only change code below this line
|
||||
a = a + 12;
|
||||
@ -91,9 +91,9 @@ c = c + 7;
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var a = 3;
|
||||
var b = 17;
|
||||
var c = 12;
|
||||
let a = 3;
|
||||
let b = 17;
|
||||
let c = 12;
|
||||
|
||||
a += 12;
|
||||
b += 9;
|
||||
|
@ -55,9 +55,9 @@ No debes modificar el código sobre el comentario especificado.
|
||||
|
||||
```js
|
||||
assert(
|
||||
/var a = 48;/.test(code) &&
|
||||
/var b = 108;/.test(code) &&
|
||||
/var c = 33;/.test(code)
|
||||
/let a = 48;/.test(code) &&
|
||||
/let b = 108;/.test(code) &&
|
||||
/let c = 33;/.test(code)
|
||||
);
|
||||
```
|
||||
|
||||
@ -72,9 +72,9 @@ assert(
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
var a = 48;
|
||||
var b = 108;
|
||||
var c = 33;
|
||||
let a = 48;
|
||||
let b = 108;
|
||||
let c = 33;
|
||||
|
||||
// Only change code below this line
|
||||
a = a / 12;
|
||||
@ -85,9 +85,9 @@ c = c / 11;
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var a = 48;
|
||||
var b = 108;
|
||||
var c = 33;
|
||||
let a = 48;
|
||||
let b = 108;
|
||||
let c = 33;
|
||||
|
||||
a /= 12;
|
||||
b /= 4;
|
||||
|
@ -55,9 +55,9 @@ No debes modificar el código sobre el comentario especificado.
|
||||
|
||||
```js
|
||||
assert(
|
||||
/var a = 5;/.test(code) &&
|
||||
/var b = 12;/.test(code) &&
|
||||
/var c = 4\.6;/.test(code)
|
||||
/let a = 5;/.test(code) &&
|
||||
/let b = 12;/.test(code) &&
|
||||
/let c = 4\.6;/.test(code)
|
||||
);
|
||||
```
|
||||
|
||||
@ -72,9 +72,9 @@ assert(
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
var a = 5;
|
||||
var b = 12;
|
||||
var c = 4.6;
|
||||
let a = 5;
|
||||
let b = 12;
|
||||
let c = 4.6;
|
||||
|
||||
// Only change code below this line
|
||||
a = a * 5;
|
||||
@ -85,9 +85,9 @@ c = c * 10;
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var a = 5;
|
||||
var b = 12;
|
||||
var c = 4.6;
|
||||
let a = 5;
|
||||
let b = 12;
|
||||
let c = 4.6;
|
||||
|
||||
a *= 5;
|
||||
b *= 3;
|
||||
|
@ -55,7 +55,7 @@ No debes modificar el código sobre el comentario especificado.
|
||||
|
||||
```js
|
||||
assert(
|
||||
/var a = 11;/.test(code) && /var b = 9;/.test(code) && /var c = 3;/.test(code)
|
||||
/let a = 11;/.test(code) && /let b = 9;/.test(code) && /let c = 3;/.test(code)
|
||||
);
|
||||
```
|
||||
|
||||
@ -70,9 +70,9 @@ assert(
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
var a = 11;
|
||||
var b = 9;
|
||||
var c = 3;
|
||||
let a = 11;
|
||||
let b = 9;
|
||||
let c = 3;
|
||||
|
||||
// Only change code below this line
|
||||
a = a - 6;
|
||||
@ -83,9 +83,9 @@ c = c - 1;
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var a = 11;
|
||||
var b = 9;
|
||||
var c = 3;
|
||||
let a = 11;
|
||||
let b = 9;
|
||||
let c = 3;
|
||||
|
||||
a -= 6;
|
||||
b -= 15;
|
||||
|
@ -16,7 +16,7 @@ También podemos utilizar el operador `+=` para <dfn>concatenar</dfn> una cadena
|
||||
Ejemplo:
|
||||
|
||||
```js
|
||||
var ourStr = "I come first. ";
|
||||
let ourStr = "I come first. ";
|
||||
ourStr += "I come second.";
|
||||
```
|
||||
|
||||
@ -57,14 +57,12 @@ assert(code.match(/myStr\s*\+=\s*(["']).*\1/g));
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
// Only change code below this line
|
||||
|
||||
var myStr;
|
||||
let myStr;
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myStr = "This is the first sentence. ";
|
||||
let myStr = "This is the first sentence. ";
|
||||
myStr += "This is the second sentence.";
|
||||
```
|
||||
|
@ -14,8 +14,8 @@ A veces necesitarás construir una cadena, al estilo [Mad Libs](https://en.wikip
|
||||
Ejemplo:
|
||||
|
||||
```js
|
||||
var ourName = "freeCodeCamp";
|
||||
var ourStr = "Hello, our name is " + ourName + ", how are you?";
|
||||
const ourName = "freeCodeCamp";
|
||||
const ourStr = "Hello, our name is " + ourName + ", how are you?";
|
||||
```
|
||||
|
||||
`ourStr` tendrá como valor la cadena `Hello, our name is freeCodeCamp, how are you?`.
|
||||
@ -63,13 +63,13 @@ assert(code.match(/["']\s*\+\s*myName\s*\+\s*["']/g).length > 0);
|
||||
|
||||
```js
|
||||
// Only change code below this line
|
||||
var myName;
|
||||
var myStr;
|
||||
const myName = "";
|
||||
const myStr = "";
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myName = "Bob";
|
||||
var myStr = "My name is " + myName + " and I am well!";
|
||||
const myName = "Bob";
|
||||
const myStr = "My name is " + myName + " and I am well!";
|
||||
```
|
||||
|
@ -159,7 +159,7 @@ assert(
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
var count = 0;
|
||||
let count = 0;
|
||||
|
||||
function cc(card) {
|
||||
// Only change code below this line
|
||||
@ -175,7 +175,7 @@ cc(2); cc(3); cc(7); cc('K'); cc('A');
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var count = 0;
|
||||
let count = 0;
|
||||
function cc(card) {
|
||||
switch(card) {
|
||||
case 2:
|
||||
|
@ -42,13 +42,14 @@ assert(myDecimal % 1 != 0);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
var ourDecimal = 5.7;
|
||||
const ourDecimal = 5.7;
|
||||
|
||||
// Only change code below this line
|
||||
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myDecimal = 9.9;
|
||||
const myDecimal = 9.9;
|
||||
```
|
||||
|
@ -39,7 +39,7 @@ assert(myVar === 10);
|
||||
|
||||
```js
|
||||
assert(
|
||||
/var\s*myVar\s*=\s*11;\s*\/*.*\s*([-]{2}\s*myVar|myVar\s*[-]{2});/.test(code)
|
||||
/let\s*myVar\s*=\s*11;\s*\/*.*\s*([-]{2}\s*myVar|myVar\s*[-]{2});/.test(code)
|
||||
);
|
||||
```
|
||||
|
||||
@ -52,7 +52,7 @@ assert(/[-]{2}\s*myVar|myVar\s*[-]{2}/.test(code));
|
||||
No debes cambiar el código por encima del comentario especificado.
|
||||
|
||||
```js
|
||||
assert(/var myVar = 11;/.test(code));
|
||||
assert(/let myVar = 11;/.test(code));
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -66,7 +66,7 @@ assert(/var myVar = 11;/.test(code));
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
var myVar = 11;
|
||||
let myVar = 11;
|
||||
|
||||
// Only change code below this line
|
||||
myVar = myVar - 1;
|
||||
@ -75,6 +75,6 @@ myVar = myVar - 1;
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myVar = 11;
|
||||
let myVar = 11;
|
||||
myVar--;
|
||||
```
|
||||
|
@ -18,7 +18,7 @@ delete ourDog.bark;
|
||||
Ejemplo:
|
||||
|
||||
```js
|
||||
var ourDog = {
|
||||
const ourDog = {
|
||||
"name": "Camper",
|
||||
"legs": 4,
|
||||
"tails": 1,
|
||||
@ -70,7 +70,7 @@ assert(code.match(/"tails": 1/g).length > 0);
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var myDog = {
|
||||
const myDog = {
|
||||
"name": "Happy Coder",
|
||||
"legs": 4,
|
||||
"tails": 1,
|
||||
@ -79,12 +79,13 @@ var myDog = {
|
||||
};
|
||||
|
||||
// Only change code below this line
|
||||
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myDog = {
|
||||
const myDog = {
|
||||
"name": "Happy Coder",
|
||||
"legs": 4,
|
||||
"tails": 1,
|
||||
|
@ -46,11 +46,11 @@ assert(code.match(/quotient/g).length === 1);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
var quotient = 0.0 / 2.0; // Change this line
|
||||
const quotient = 0.0 / 2.0; // Change this line
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var quotient = 4.4 / 2.0;
|
||||
const quotient = 4.4 / 2.0;
|
||||
```
|
||||
|
@ -16,7 +16,7 @@ JavaScript utiliza el símbolo `/` para la división.
|
||||
**Ejemplo**
|
||||
|
||||
```js
|
||||
myVar = 16 / 2;
|
||||
const myVar = 16 / 2;
|
||||
```
|
||||
|
||||
`myVar` ahora tiene el valor `8`.
|
||||
@ -49,11 +49,11 @@ assert(/\d+\s*\/\s*\d+/.test(code));
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
var quotient = 66 / 0;
|
||||
const quotient = 66 / 0;
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var quotient = 66 / 33;
|
||||
const quotient = 66 / 33;
|
||||
```
|
||||
|
@ -89,11 +89,11 @@ console.log('myStr:\n' + myStr);}})();
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
var myStr; // Change this line
|
||||
const myStr = ""; // Change this line
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myStr = "FirstLine\n\t\\SecondLine\nThirdLine";
|
||||
const myStr = "FirstLine\n\t\\SecondLine\nThirdLine";
|
||||
```
|
||||
|
@ -14,7 +14,7 @@ Cuando estás definiendo una cadena debes comenzar y terminar con una comilla si
|
||||
En JavaScript, puedes <dfn>escapar</dfn> una comilla de considerarse un final de cadena colocando una <dfn>barra invertida</dfn> (`\`) delante de la comilla.
|
||||
|
||||
```js
|
||||
var sampleStr = "Alan said, \"Peter is learning JavaScript\".";
|
||||
const sampleStr = "Alan said, \"Peter is learning JavaScript\".";
|
||||
```
|
||||
|
||||
Esto indica a JavaScript que la siguiente comilla no es el final de la cadena, sino que debería aparecer dentro de la cadena. Así que si imprimieras esto en la consola, obtendrías:
|
||||
@ -62,11 +62,11 @@ assert(/I am a "double quoted" string inside "double quotes(\."|"\.)$/.test(mySt
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
var myStr = ""; // Change this line
|
||||
const myStr = ""; // Change this line
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myStr = "I am a \"double quoted\" string inside \"double quotes\".";
|
||||
const myStr = "I am a \"double quoted\" string inside \"double quotes\".";
|
||||
```
|
||||
|
@ -31,7 +31,7 @@ Establece `remainder` igual al resto de `11` dividido entre `3` usando el operad
|
||||
La variable `remainder` debe inicializarse
|
||||
|
||||
```js
|
||||
assert(/var\s+?remainder/.test(code));
|
||||
assert(/(const|let|var)\s+?remainder/.test(code));
|
||||
```
|
||||
|
||||
El valor de `remainder` debe ser `2`
|
||||
@ -57,13 +57,11 @@ assert(/\s+?remainder\s*?=\s*?.*%.*;?/.test(code));
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
// Only change code below this line
|
||||
|
||||
var remainder;
|
||||
const remainder = 0;
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var remainder = 11 % 3;
|
||||
const remainder = 11 % 3;
|
||||
```
|
||||
|
@ -14,9 +14,10 @@ Es posible tener variables <dfn>locales</dfn> y <dfn>globales</dfn> con el mismo
|
||||
En este ejemplo:
|
||||
|
||||
```js
|
||||
var someVar = "Hat";
|
||||
const someVar = "Hat";
|
||||
|
||||
function myFun() {
|
||||
var someVar = "Head";
|
||||
const someVar = "Head";
|
||||
return someVar;
|
||||
}
|
||||
```
|
||||
@ -53,13 +54,11 @@ assert(/return outerWear/.test(code));
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var outerWear = "T-Shirt";
|
||||
const outerWear = "T-Shirt";
|
||||
|
||||
function myOutfit() {
|
||||
// Only change code below this line
|
||||
|
||||
|
||||
|
||||
// Only change code above this line
|
||||
return outerWear;
|
||||
}
|
||||
@ -70,9 +69,9 @@ myOutfit();
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var outerWear = "T-Shirt";
|
||||
const outerWear = "T-Shirt";
|
||||
function myOutfit() {
|
||||
var outerWear = "sweater";
|
||||
const outerWear = "sweater";
|
||||
return outerWear;
|
||||
}
|
||||
```
|
||||
|
@ -90,7 +90,8 @@ assert(golfScore(5, 9) === 'Go Home!');
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
var names = ["Hole-in-one!", "Eagle", "Birdie", "Par", "Bogey", "Double Bogey", "Go Home!"];
|
||||
const names = ["Hole-in-one!", "Eagle", "Birdie", "Par", "Bogey", "Double Bogey", "Go Home!"];
|
||||
|
||||
function golfScore(par, strokes) {
|
||||
// Only change code below this line
|
||||
|
||||
|
@ -39,7 +39,7 @@ No debes utilizar el operador de asignación.
|
||||
|
||||
```js
|
||||
assert(
|
||||
/var\s*myVar\s*=\s*87;\s*\/*.*\s*([+]{2}\s*myVar|myVar\s*[+]{2});/.test(code)
|
||||
/let\s*myVar\s*=\s*87;\s*\/*.*\s*([+]{2}\s*myVar|myVar\s*[+]{2});/.test(code)
|
||||
);
|
||||
```
|
||||
|
||||
@ -52,7 +52,7 @@ assert(/[+]{2}\s*myVar|myVar\s*[+]{2}/.test(code));
|
||||
No debes cambiar el código por encima del comentario especificado.
|
||||
|
||||
```js
|
||||
assert(/var myVar = 87;/.test(code));
|
||||
assert(/let myVar = 87;/.test(code));
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -66,7 +66,7 @@ assert(/var myVar = 87;/.test(code));
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
var myVar = 87;
|
||||
let myVar = 87;
|
||||
|
||||
// Only change code below this line
|
||||
myVar = myVar + 1;
|
||||
@ -75,6 +75,6 @@ myVar = myVar + 1;
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myVar = 87;
|
||||
let myVar = 87;
|
||||
myVar++;
|
||||
```
|
||||
|
@ -64,7 +64,7 @@ assert(testElse(10) === 'Bigger than 5');
|
||||
No debes cambiar el código por encima o por debajo de los comentarios especificados.
|
||||
|
||||
```js
|
||||
assert(/var result = "";/.test(code) && /return result;/.test(code));
|
||||
assert(/let result = "";/.test(code) && /return result;/.test(code));
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -73,7 +73,7 @@ assert(/var result = "";/.test(code) && /return result;/.test(code));
|
||||
|
||||
```js
|
||||
function testElse(val) {
|
||||
var result = "";
|
||||
let result = "";
|
||||
// Only change code below this line
|
||||
|
||||
if (val > 5) {
|
||||
@ -95,7 +95,7 @@ testElse(4);
|
||||
|
||||
```js
|
||||
function testElse(val) {
|
||||
var result = "";
|
||||
let result = "";
|
||||
if(val > 5) {
|
||||
result = "Bigger than 5";
|
||||
} else {
|
||||
|
@ -12,8 +12,9 @@ dashedName: iterate-through-an-array-with-a-for-loop
|
||||
Una tarea común en JavaScript es iterar a través del contenido de un arreglo. Una forma de hacerlo es con un bucle `for`. Este código mostrará cada elemento del arreglo `arr` en la consola:
|
||||
|
||||
```js
|
||||
var arr = [10, 9, 8, 7, 6];
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
const arr = [10, 9, 8, 7, 6];
|
||||
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
console.log(arr[i]);
|
||||
}
|
||||
```
|
||||
@ -62,18 +63,19 @@ assert(!__helpers.removeWhiteSpace(code).match(/total[=+-]0*[1-9]+/gm));
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var myArr = [ 2, 3, 4, 5, 6];
|
||||
const myArr = [2, 3, 4, 5, 6];
|
||||
|
||||
// Only change code below this line
|
||||
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myArr = [ 2, 3, 4, 5, 6];
|
||||
var total = 0;
|
||||
const myArr = [2, 3, 4, 5, 6];
|
||||
let total = 0;
|
||||
|
||||
for (var i = 0; i < myArr.length; i++) {
|
||||
for (let i = 0; i < myArr.length; i++) {
|
||||
total += myArr[i];
|
||||
}
|
||||
```
|
||||
|
@ -12,8 +12,9 @@ dashedName: iterate-with-javascript-do---while-loops
|
||||
El siguiente tipo de bucle que aprenderás se llama bucle `do...while`. Se llama bucle `do...while` porque primero hace (`do`) una pasada por el código dentro del bucle sin importar qué, y luego continua ejecutando el bucle mientras (`while`) la condición especificada sea verdadera (`true`).
|
||||
|
||||
```js
|
||||
var ourArray = [];
|
||||
var i = 0;
|
||||
const ourArray = [];
|
||||
let i = 0;
|
||||
|
||||
do {
|
||||
ourArray.push(i);
|
||||
i++;
|
||||
@ -23,8 +24,9 @@ do {
|
||||
El ejemplo anterior se comporta de forma similar a otros tipos de bucles, siendo el arreglo resultante `[0, 1, 2, 3, 4]`. Sin embargo, lo que hace que el bucle `do...while` sea diferente a otros bucles es cómo se comporta cuando la condición falla en la primera verificación. Veamos esto en acción: Aquí puedes ver un bucle `while` que ejecutará el código una y otra vez siempre que `i < 5`:
|
||||
|
||||
```js
|
||||
var ourArray = [];
|
||||
var i = 5;
|
||||
const ourArray = [];
|
||||
let i = 5;
|
||||
|
||||
while (i < 5) {
|
||||
ourArray.push(i);
|
||||
i++;
|
||||
@ -34,8 +36,9 @@ while (i < 5) {
|
||||
En este ejemplo, inicializamos el valor de `ourArray` a un arreglo vacío y el valor de `i` a 5. Cuando ejecutamos el bucle `while`, la condición se evalúa como `false` porque `i` no es inferior a 5, así que no ejecutamos el código dentro del bucle. El resultado es que `ourArray` terminará sin valores añadidos, y todavía se verá como `[]` una vez el código del ejemplo anterior haya terminado de ejecutarse. Ahora, dale un vistazo a un bucle `do...while`:
|
||||
|
||||
```js
|
||||
var ourArray = [];
|
||||
var i = 5;
|
||||
const ourArray = [];
|
||||
let i = 5;
|
||||
|
||||
do {
|
||||
ourArray.push(i);
|
||||
i++;
|
||||
@ -80,8 +83,8 @@ if(typeof myArray !== "undefined"){(function(){return myArray;})();}
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var myArray = [];
|
||||
var i = 10;
|
||||
const myArray = [];
|
||||
let i = 10;
|
||||
|
||||
// Only change code below this line
|
||||
while (i < 5) {
|
||||
@ -93,8 +96,8 @@ while (i < 5) {
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myArray = [];
|
||||
var i = 10;
|
||||
const myArray = [];
|
||||
let i = 10;
|
||||
do {
|
||||
myArray.push(i);
|
||||
i++;
|
||||
|
@ -15,9 +15,10 @@ Esta es una función `myTest` con una variable local llamada `loc`.
|
||||
|
||||
```js
|
||||
function myTest() {
|
||||
var loc = "foo";
|
||||
const loc = "foo";
|
||||
console.log(loc);
|
||||
}
|
||||
|
||||
myTest();
|
||||
console.log(loc);
|
||||
```
|
||||
@ -38,6 +39,7 @@ El código no debe contener una variable global `myVar`.
|
||||
function declared() {
|
||||
myVar;
|
||||
}
|
||||
|
||||
assert.throws(declared, ReferenceError);
|
||||
```
|
||||
|
||||
@ -57,7 +59,6 @@ assert(
|
||||
|
||||
```js
|
||||
function myLocalScope() {
|
||||
|
||||
// Only change code below this line
|
||||
|
||||
console.log('inside myLocalScope', myVar);
|
||||
@ -73,9 +74,8 @@ console.log('outside myLocalScope', myVar);
|
||||
|
||||
```js
|
||||
function myLocalScope() {
|
||||
|
||||
// Only change code below this line
|
||||
var myVar;
|
||||
let myVar;
|
||||
console.log('inside myLocalScope', myVar);
|
||||
}
|
||||
myLocalScope();
|
||||
|
@ -16,10 +16,10 @@ Una forma fácil de añadir datos al final de un arreglo es a través de la func
|
||||
Ejemplos:
|
||||
|
||||
```js
|
||||
var arr1 = [1,2,3];
|
||||
const arr1 = [1, 2, 3];
|
||||
arr1.push(4);
|
||||
|
||||
var arr2 = ["Stimpson", "J", "cat"];
|
||||
const arr2 = ["Stimpson", "J", "cat"];
|
||||
arr2.push(["happy", "joy"]);
|
||||
```
|
||||
|
||||
@ -64,14 +64,15 @@ assert(
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var myArray = [["John", 23], ["cat", 2]];
|
||||
const myArray = [["John", 23], ["cat", 2]];
|
||||
|
||||
// Only change code below this line
|
||||
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myArray = [["John", 23], ["cat", 2]];
|
||||
const myArray = [["John", 23], ["cat", 2]];
|
||||
myArray.push(["dog",3]);
|
||||
```
|
||||
|
@ -14,7 +14,7 @@ A veces, es posible que desees almacenar datos en una <dfn>estructura de datos</
|
||||
Este es un ejemplo de una estructura de datos compleja:
|
||||
|
||||
```js
|
||||
var ourMusic = [
|
||||
const ourMusic = [
|
||||
{
|
||||
"artist": "Daft Punk",
|
||||
"title": "Homework",
|
||||
@ -135,7 +135,7 @@ myMusic.forEach(object => {
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
var myMusic = [
|
||||
const myMusic = [
|
||||
{
|
||||
"artist": "Billy Joel",
|
||||
"title": "Piano Man",
|
||||
@ -153,7 +153,7 @@ var myMusic = [
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myMusic = [
|
||||
const myMusic = [
|
||||
{
|
||||
"artist": "Billy Joel",
|
||||
"title": "Piano Man",
|
||||
|
@ -12,7 +12,7 @@ dashedName: multiple-identical-options-in-switch-statements
|
||||
Si la sentencia `break` es omitida en un caso (`case`) de una sentencia `switch`, las siguientes sentencias `case` serán ejecutadas hasta encontrar un `break`. Si tienes múltiples entradas con la misma salida, puedes representarlas en una sentencia `switch` como esta:
|
||||
|
||||
```js
|
||||
var result = "";
|
||||
let result = "";
|
||||
switch(val) {
|
||||
case 1:
|
||||
case 2:
|
||||
@ -109,7 +109,7 @@ assert(code.match(/case/g).length === 9);
|
||||
|
||||
```js
|
||||
function sequentialSizes(val) {
|
||||
var answer = "";
|
||||
let answer = "";
|
||||
// Only change code below this line
|
||||
|
||||
|
||||
@ -125,7 +125,7 @@ sequentialSizes(1);
|
||||
|
||||
```js
|
||||
function sequentialSizes(val) {
|
||||
var answer = "";
|
||||
let answer = "";
|
||||
|
||||
switch(val) {
|
||||
case 1:
|
||||
|
@ -42,11 +42,11 @@ assert(/\*/.test(code));
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
var product = 2.0 * 0.0;
|
||||
const product = 2.0 * 0.0;
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var product = 2.0 * 2.5;
|
||||
const product = 2.0 * 2.5;
|
||||
```
|
||||
|
@ -16,7 +16,7 @@ JavaScript utiliza el símbolo `*` para multiplicar dos números.
|
||||
**Ejemplo**
|
||||
|
||||
```js
|
||||
myVar = 13 * 13;
|
||||
const myVar = 13 * 13;
|
||||
```
|
||||
|
||||
`myVar` ahora tendrá el valor `169`.
|
||||
@ -50,11 +50,11 @@ assert(/\*/.test(code));
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
var product = 8 * 0;
|
||||
const product = 8 * 0;
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var product = 8 * 10;
|
||||
const product = 8 * 10;
|
||||
```
|
||||
|
@ -12,7 +12,7 @@ dashedName: nest-one-array-within-another-array
|
||||
También puedes anidar arreglos dentro de otros arreglos, como a continuación:
|
||||
|
||||
```js
|
||||
[["Bulls", 23], ["White Sox", 45]]
|
||||
const teams = [["Bulls", 23], ["White Sox", 45]];
|
||||
```
|
||||
|
||||
Esto también es conocido como <dfn>arreglo multidimensional</dfn>.
|
||||
@ -41,11 +41,11 @@ if(typeof myArray !== "undefined"){(function(){return myArray;})();}
|
||||
|
||||
```js
|
||||
// Only change code below this line
|
||||
var myArray = [];
|
||||
const myArray = [];
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myArray = [[1,2,3]];
|
||||
const myArray = [[1, 2, 3]];
|
||||
```
|
||||
|
@ -68,34 +68,33 @@ assert(lookUpProfile('Akira', 'address') === 'No such property');
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var contacts = [
|
||||
{
|
||||
"firstName": "Akira",
|
||||
"lastName": "Laine",
|
||||
"number": "0543236543",
|
||||
"likes": ["Pizza", "Coding", "Brownie Points"]
|
||||
},
|
||||
{
|
||||
"firstName": "Harry",
|
||||
"lastName": "Potter",
|
||||
"number": "0994372684",
|
||||
"likes": ["Hogwarts", "Magic", "Hagrid"]
|
||||
},
|
||||
{
|
||||
"firstName": "Sherlock",
|
||||
"lastName": "Holmes",
|
||||
"number": "0487345643",
|
||||
"likes": ["Intriguing Cases", "Violin"]
|
||||
},
|
||||
{
|
||||
"firstName": "Kristian",
|
||||
"lastName": "Vos",
|
||||
"number": "unknown",
|
||||
"likes": ["JavaScript", "Gaming", "Foxes"]
|
||||
}
|
||||
const contacts = [
|
||||
{
|
||||
firstName: "Akira",
|
||||
lastName: "Laine",
|
||||
number: "0543236543",
|
||||
likes: ["Pizza", "Coding", "Brownie Points"],
|
||||
},
|
||||
{
|
||||
firstName: "Harry",
|
||||
lastName: "Potter",
|
||||
number: "0994372684",
|
||||
likes: ["Hogwarts", "Magic", "Hagrid"],
|
||||
},
|
||||
{
|
||||
firstName: "Sherlock",
|
||||
lastName: "Holmes",
|
||||
number: "0487345643",
|
||||
likes: ["Intriguing Cases", "Violin"],
|
||||
},
|
||||
{
|
||||
firstName: "Kristian",
|
||||
lastName: "Vos",
|
||||
number: "unknown",
|
||||
likes: ["JavaScript", "Gaming", "Foxes"],
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
function lookUpProfile(name, prop) {
|
||||
// Only change code below this line
|
||||
|
||||
@ -108,44 +107,38 @@ lookUpProfile("Akira", "likes");
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var contacts = [
|
||||
{
|
||||
"firstName": "Akira",
|
||||
"lastName": "Laine",
|
||||
"number": "0543236543",
|
||||
"likes": ["Pizza", "Coding", "Brownie Points"]
|
||||
},
|
||||
{
|
||||
"firstName": "Harry",
|
||||
"lastName": "Potter",
|
||||
"number": "0994372684",
|
||||
"likes": ["Hogwarts", "Magic", "Hagrid"]
|
||||
},
|
||||
{
|
||||
"firstName": "Sherlock",
|
||||
"lastName": "Holmes",
|
||||
"number": "0487345643",
|
||||
"likes": ["Intriguing Cases", "Violin"]
|
||||
},
|
||||
{
|
||||
"firstName": "Kristian",
|
||||
"lastName": "Vos",
|
||||
"number": "unknown",
|
||||
"likes": ["JavaScript", "Gaming", "Foxes"]
|
||||
},
|
||||
const contacts = [
|
||||
{
|
||||
firstName: "Akira",
|
||||
lastName: "Laine",
|
||||
number: "0543236543",
|
||||
likes: ["Pizza", "Coding", "Brownie Points"],
|
||||
},
|
||||
{
|
||||
firstName: "Harry",
|
||||
lastName: "Potter",
|
||||
number: "0994372684",
|
||||
likes: ["Hogwarts", "Magic", "Hagrid"],
|
||||
},
|
||||
{
|
||||
firstName: "Sherlock",
|
||||
lastName: "Holmes",
|
||||
number: "0487345643",
|
||||
likes: ["Intriguing Cases", "Violin"],
|
||||
},
|
||||
{
|
||||
firstName: "Kristian",
|
||||
lastName: "Vos",
|
||||
number: "unknown",
|
||||
likes: ["JavaScript", "Gaming", "Foxes"],
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
//Write your function in between these comments
|
||||
function lookUpProfile(name, prop){
|
||||
for(var i in contacts){
|
||||
if(contacts[i].firstName === name) {
|
||||
return contacts[i][prop] || "No such property";
|
||||
}
|
||||
function lookUpProfile(name, prop) {
|
||||
for (let i in contacts) {
|
||||
if (contacts[i].firstName === name) {
|
||||
return contacts[i][prop] || "No such property";
|
||||
}
|
||||
return "No such contact";
|
||||
}
|
||||
return "No such contact";
|
||||
}
|
||||
//Write your function in between these comments
|
||||
|
||||
lookUpProfile("Akira", "likes");
|
||||
```
|
||||
|
@ -12,21 +12,21 @@ dashedName: quoting-strings-with-single-quotes
|
||||
Los valores de <dfn>cadena</dfn> en JavaScript pueden escribirse con comillas simples o dobles, siempre y cuando comiencen y terminen con el mismo tipo de comillas. A diferencia de otros lenguajes de programación, las comillas simples y dobles funcionan igual en JavaScript.
|
||||
|
||||
```js
|
||||
doubleQuoteStr = "This is a string";
|
||||
singleQuoteStr = 'This is also a string';
|
||||
const doubleQuoteStr = "This is a string";
|
||||
const singleQuoteStr = 'This is also a string';
|
||||
```
|
||||
|
||||
La razón por la que puedes querer usar un tipo de comilla sobre otro es si quieres usar ambos en una cadena. Esto puede suceder si quieres guardar una conversación en una cadena y tener la conversación entre comillas. Otro uso sería guardar una etiqueta `<a>` con varios atributos entre comillas, todo dentro de una cadena.
|
||||
|
||||
```js
|
||||
conversation = 'Finn exclaims to Jake, "Algebraic!"';
|
||||
const conversation = 'Finn exclaims to Jake, "Algebraic!"';
|
||||
```
|
||||
|
||||
Sin embargo, esto se convierte en un problema cuando es necesario utilizar las comillas externas dentro de ella. Recuerda, una cadena tiene el mismo tipo de comillas al principio y al final. Pero si tienes esa misma comilla en algún lugar del medio, la cadena se detendrá antes de tiempo y arrojará un error.
|
||||
|
||||
```js
|
||||
goodStr = 'Jake asks Finn, "Hey, let\'s go on an adventure?"';
|
||||
badStr = 'Finn responds, "Let's go!"';
|
||||
const goodStr = 'Jake asks Finn, "Hey, let\'s go on an adventure?"';
|
||||
const badStr = 'Finn responds, "Let's go!"';
|
||||
```
|
||||
|
||||
Aquí `badStr` arrojará un error.
|
||||
@ -71,11 +71,11 @@ assert(code.match(/"/g).length === 4 && code.match(/'/g).length === 2);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
var myStr = "<a href=\"http://www.example.com\" target=\"_blank\">Link</a>";
|
||||
const myStr = "<a href=\"http://www.example.com\" target=\"_blank\">Link</a>";
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myStr = '<a href="http://www.example.com" target="_blank">Link</a>';
|
||||
const myStr = '<a href="http://www.example.com" target="_blank">Link</a>';
|
||||
```
|
||||
|
@ -115,7 +115,7 @@ const _recordCollection = {
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var recordCollection = {
|
||||
const recordCollection = {
|
||||
2548: {
|
||||
albumTitle: 'Slippery When Wet',
|
||||
artist: 'Bon Jovi',
|
||||
@ -146,7 +146,7 @@ updateRecords(recordCollection, 5439, 'artist', 'ABBA');
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var recordCollection = {
|
||||
const recordCollection = {
|
||||
2548: {
|
||||
albumTitle: 'Slippery When Wet',
|
||||
artist: 'Bon Jovi',
|
||||
|
@ -14,9 +14,9 @@ La recursión es el concepto que una función puede expresarse en términos de s
|
||||
|
||||
```js
|
||||
function multiply(arr, n) {
|
||||
var product = 1;
|
||||
for (var i = 0; i < n; i++) {
|
||||
product *= arr[i];
|
||||
let product = 1;
|
||||
for (let i = 0; i < n; i++) {
|
||||
product *= arr[i];
|
||||
}
|
||||
return product;
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ assert(chainToSwitch(156) === '');
|
||||
|
||||
```js
|
||||
function chainToSwitch(val) {
|
||||
var answer = "";
|
||||
let answer = "";
|
||||
// Only change code below this line
|
||||
|
||||
if (val === "bob") {
|
||||
@ -134,7 +134,7 @@ chainToSwitch(7);
|
||||
|
||||
```js
|
||||
function chainToSwitch(val) {
|
||||
var answer = "";
|
||||
let answer = "";
|
||||
|
||||
switch(val) {
|
||||
case "bob":
|
||||
|
@ -17,7 +17,8 @@ Podemos pasar valores a una función con <dfn>argumentos</dfn>. Puedes utilizar
|
||||
function plusThree(num) {
|
||||
return num + 3;
|
||||
}
|
||||
var answer = plusThree(5);
|
||||
|
||||
const answer = plusThree(5);
|
||||
```
|
||||
|
||||
`answer` tiene el valor `8`.
|
||||
|
@ -78,7 +78,7 @@ assert(code.match(/break/g).length > 2);
|
||||
|
||||
```js
|
||||
function caseInSwitch(val) {
|
||||
var answer = "";
|
||||
let answer = "";
|
||||
// Only change code below this line
|
||||
|
||||
|
||||
@ -94,7 +94,7 @@ caseInSwitch(1);
|
||||
|
||||
```js
|
||||
function caseInSwitch(val) {
|
||||
var answer = "";
|
||||
let answer = "";
|
||||
|
||||
switch(val) {
|
||||
case 1:
|
||||
|
@ -81,13 +81,13 @@ var hasNumber = false;
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
var myList = [];
|
||||
const myList = [];
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myList = [
|
||||
const myList = [
|
||||
["Candy", 10],
|
||||
["Potatoes", 12],
|
||||
["Eggs", 12],
|
||||
|
@ -93,12 +93,10 @@ function nextInLine(arr, item) {
|
||||
|
||||
return item;
|
||||
// Only change code above this line
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Setup
|
||||
var testArr = [1,2,3,4,5];
|
||||
const testArr = [1, 2, 3, 4, 5];
|
||||
|
||||
// Display code
|
||||
console.log("Before: " + JSON.stringify(testArr));
|
||||
@ -109,7 +107,7 @@ console.log("After: " + JSON.stringify(testArr));
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var testArr = [ 1,2,3,4,5];
|
||||
const testArr = [1, 2, 3, 4, 5];
|
||||
|
||||
function nextInLine(arr, item) {
|
||||
arr.push(item);
|
||||
|
@ -14,7 +14,7 @@ Con las variables de arreglos (`array`) de JavaScript, podemos almacenar varios
|
||||
Inicias una declaración de arreglo con un corchete de apertura, lo terminas con un corchete de cierre, y pones una coma entre cada entrada, de esta forma:
|
||||
|
||||
```js
|
||||
var sandwich = ["peanut butter", "jelly", "bread"]
|
||||
const sandwich = ["peanut butter", "jelly", "bread"];
|
||||
```
|
||||
|
||||
# --instructions--
|
||||
@ -53,11 +53,11 @@ assert(typeof myArray[1] !== 'undefined' && typeof myArray[1] == 'number');
|
||||
|
||||
```js
|
||||
// Only change code below this line
|
||||
var myArray = [];
|
||||
const myArray = [];
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myArray = ["The Answer", 42];
|
||||
const myArray = ["The Answer", 42];
|
||||
```
|
||||
|
@ -16,7 +16,7 @@ JavaScript utiliza el símbolo `-` para restar.
|
||||
**Ejemplo**
|
||||
|
||||
```js
|
||||
myVar = 12 - 6;
|
||||
const myVar = 12 - 6;
|
||||
```
|
||||
|
||||
`myVar` tendrá el valor `6`.
|
||||
@ -49,11 +49,11 @@ assert(/difference=45-33;?/.test(__helpers.removeWhiteSpace(code)));
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
var difference = 45 - 0;
|
||||
const difference = 45 - 0;
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var difference = 45 - 33;
|
||||
const difference = 45 - 33;
|
||||
```
|
||||
|
@ -13,10 +13,11 @@ A veces es útil comprobar si existe o no la propiedad de un objeto dado. Podemo
|
||||
**Por ejemplo**
|
||||
|
||||
```js
|
||||
var myObj = {
|
||||
const myObj = {
|
||||
top: "hat",
|
||||
bottom: "pants"
|
||||
};
|
||||
|
||||
myObj.hasOwnProperty("top");
|
||||
myObj.hasOwnProperty("middle");
|
||||
```
|
||||
|
@ -14,14 +14,14 @@ En JavaScript, los valores de cadena (`String`) son <dfn>inmutables</dfn>, lo qu
|
||||
Por ejemplo, el siguiente código:
|
||||
|
||||
```js
|
||||
var myStr = "Bob";
|
||||
let myStr = "Bob";
|
||||
myStr[0] = "J";
|
||||
```
|
||||
|
||||
no puede cambiar el valor de `myStr` a `Job`, porque el contenido de `myStr` no puede ser alterado. Ten en cuenta que esto *no* significa que `myStr` no puede cambiarse, solo que los caracteres individuales de una <dfn>cadena literal</dfn> no pueden ser cambiados. La única forma de cambiar `myStr` sería asignarla con una nueva cadena, como esta:
|
||||
|
||||
```js
|
||||
var myStr = "Bob";
|
||||
let myStr = "Bob";
|
||||
myStr = "Job";
|
||||
```
|
||||
|
||||
@ -55,7 +55,7 @@ assert(/myStr = "Jello World"/.test(code));
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var myStr = "Jello World";
|
||||
let myStr = "Jello World";
|
||||
|
||||
// Only change code below this line
|
||||
myStr[0] = "H"; // Change this line
|
||||
@ -65,6 +65,6 @@ myStr[0] = "H"; // Change this line
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myStr = "Jello World";
|
||||
let myStr = "Jello World";
|
||||
myStr = "Hello World";
|
||||
```
|
||||
|
@ -43,7 +43,6 @@ welcomeToBooleans();
|
||||
|
||||
```js
|
||||
function welcomeToBooleans() {
|
||||
|
||||
// Only change code below this line
|
||||
|
||||
return false; // Change this line
|
||||
|
@ -14,10 +14,12 @@ Una función puede incluir la declaración de devolución (`return`) pero no tie
|
||||
**Ejemplo**
|
||||
|
||||
```js
|
||||
var sum = 0;
|
||||
let sum = 0;
|
||||
|
||||
function addSum(num) {
|
||||
sum = sum + num;
|
||||
}
|
||||
|
||||
addSum(3);
|
||||
```
|
||||
|
||||
@ -61,7 +63,7 @@ assert(
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var sum = 0;
|
||||
let sum = 0;
|
||||
|
||||
function addThree() {
|
||||
sum = sum + 3;
|
||||
@ -79,7 +81,7 @@ addFive();
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var sum = 0;
|
||||
let sum = 0;
|
||||
|
||||
function addThree() {
|
||||
sum = sum + 3;
|
||||
|
@ -14,7 +14,7 @@ Después de haber creado un objeto de JavaScript, puedes actualizar sus propieda
|
||||
Por ejemplo, veamos `ourDog`:
|
||||
|
||||
```js
|
||||
var ourDog = {
|
||||
const ourDog = {
|
||||
"name": "Camper",
|
||||
"legs": 4,
|
||||
"tails": 1,
|
||||
@ -54,7 +54,7 @@ assert(/"name": "Coder"/.test(code));
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var myDog = {
|
||||
const myDog = {
|
||||
"name": "Coder",
|
||||
"legs": 4,
|
||||
"tails": 1,
|
||||
@ -62,12 +62,13 @@ var myDog = {
|
||||
};
|
||||
|
||||
// Only change code below this line
|
||||
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myDog = {
|
||||
const myDog = {
|
||||
"name": "Coder",
|
||||
"legs": 4,
|
||||
"tails": 1,
|
||||
|
@ -16,8 +16,8 @@ Recuerda que las computadoras empiezan a contar desde `0`, así que el primer ca
|
||||
Ejemplo:
|
||||
|
||||
```js
|
||||
var firstName = "Ada";
|
||||
var secondLetterOfFirstName = firstName[1];
|
||||
const firstName = "Ada";
|
||||
const secondLetterOfFirstName = firstName[1];
|
||||
```
|
||||
|
||||
`secondLetterOfFirstName` tendrá una cadena con valor `d`.
|
||||
@ -54,15 +54,15 @@ assert(code.match(/thirdLetterOfLastName\s*?=\s*?lastName\[.*?\]/));
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var lastName = "Lovelace";
|
||||
const lastName = "Lovelace";
|
||||
|
||||
// Only change code below this line
|
||||
var thirdLetterOfLastName = lastName; // Change this line
|
||||
const thirdLetterOfLastName = lastName; // Change this line
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var lastName = "Lovelace";
|
||||
var thirdLetterOfLastName = lastName[2];
|
||||
const lastName = "Lovelace";
|
||||
const thirdLetterOfLastName = lastName[2];
|
||||
```
|
||||
|
@ -73,7 +73,7 @@ function rangeOfNumbers(startNum, endNum) {
|
||||
if (endNum - startNum === 0) {
|
||||
return [startNum];
|
||||
} else {
|
||||
var numbers = rangeOfNumbers(startNum, endNum - 1);
|
||||
const numbers = rangeOfNumbers(startNum, endNum - 1);
|
||||
numbers.push(endNum);
|
||||
return numbers;
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ parseInt(string, radix);
|
||||
Y aquí hay un ejemplo:
|
||||
|
||||
```js
|
||||
var a = parseInt("11", 2);
|
||||
const a = parseInt("11", 2);
|
||||
```
|
||||
|
||||
La variable radix indica que `11` está en el sistema binario, o base 2. Este ejemplo convierte la cadena `11` a un entero `3`.
|
||||
|
@ -12,7 +12,7 @@ dashedName: use-the-parseint-function
|
||||
La función `parseInt()` analiza una cadena y devuelve un entero. A continuación, te presentamos un ejemplo:
|
||||
|
||||
```js
|
||||
var a = parseInt("007");
|
||||
const a = parseInt("007");
|
||||
```
|
||||
|
||||
La función anterior convierte la cadena `007` al entero `7`. Si el primer carácter de la cadena no puede ser convertido en un número, entonces devuelve `NaN`.
|
||||
|
@ -14,7 +14,7 @@ Los objetos pueden ser considerados como un almacenamiento clave/valor, como un
|
||||
Aquí hay un ejemplo de una simple búsqueda de alfabeto inverso:
|
||||
|
||||
```js
|
||||
var alpha = {
|
||||
const alpha = {
|
||||
1:"Z",
|
||||
2:"Y",
|
||||
3:"X",
|
||||
@ -24,10 +24,11 @@ var alpha = {
|
||||
25:"B",
|
||||
26:"A"
|
||||
};
|
||||
|
||||
alpha[2];
|
||||
alpha[24];
|
||||
|
||||
var value = 2;
|
||||
const value = 2;
|
||||
alpha[value];
|
||||
```
|
||||
|
||||
@ -102,7 +103,7 @@ assert(
|
||||
```js
|
||||
// Setup
|
||||
function phoneticLookup(val) {
|
||||
var result = "";
|
||||
let result = "";
|
||||
|
||||
// Only change code below this line
|
||||
switch(val) {
|
||||
@ -136,9 +137,9 @@ phoneticLookup("charlie");
|
||||
|
||||
```js
|
||||
function phoneticLookup(val) {
|
||||
var result = "";
|
||||
let result = "";
|
||||
|
||||
var lookup = {
|
||||
const lookup = {
|
||||
alpha: "Adams",
|
||||
bravo: "Boston",
|
||||
charlie: "Chicago",
|
||||
|
@ -16,7 +16,7 @@ En un juego de "Mad Libs", se te proporcionan oraciones con algunas palabras fal
|
||||
Considera esta oración: It was really **\_\_\_\_**, and we **\_\_\_\_** ourselves **\_\_\_\_**. Esta oración tiene tres piezas faltantes: un adjetivo, un verbo y un adverbio, y podemos añadir palabras de nuestra elección para completarla. A continuación, podemos asignar la oración completa a una variable de la siguiente manera:
|
||||
|
||||
```js
|
||||
var sentence = "It was really " + "hot" + ", and we " + "laughed" + " ourselves " + "silly" + ".";
|
||||
const sentence = "It was really " + "hot" + ", and we " + "laughed" + " ourselves " + "silly" + ".";
|
||||
```
|
||||
|
||||
# --instructions--
|
||||
@ -84,24 +84,24 @@ const removeAssignments = str => str
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
var myNoun = "dog";
|
||||
var myAdjective = "big";
|
||||
var myVerb = "ran";
|
||||
var myAdverb = "quickly";
|
||||
const myNoun = "dog";
|
||||
const myAdjective = "big";
|
||||
const myVerb = "ran";
|
||||
const myAdverb = "quickly";
|
||||
|
||||
// Only change code below this line
|
||||
var wordBlanks = ""; // Change this line
|
||||
const wordBlanks = ""; // Change this line
|
||||
// Only change code above this line
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var myNoun = "dog";
|
||||
var myAdjective = "big";
|
||||
var myVerb = "ran";
|
||||
var myAdverb = "quickly";
|
||||
const myNoun = "dog";
|
||||
const myAdjective = "big";
|
||||
const myVerb = "ran";
|
||||
const myAdverb = "quickly";
|
||||
|
||||
var wordBlanks = "Once there was a " + myNoun + " which was very " + myAdjective + ". ";
|
||||
let wordBlanks = "Once there was a " + myNoun + " which was very " + myAdjective + ". ";
|
||||
wordBlanks += "It " + myVerb + " " + myAdverb + " around the yard.";
|
||||
```
|
||||
|
Reference in New Issue
Block a user