chore(i18n,curriculum): update translations
This commit is contained in:
committed by
Mrugesh Mohapatra
parent
e139fbcf13
commit
c1fb339bbc
@ -18,9 +18,9 @@ Os índices de um array são escritos na mesma notação com colchetes que as st
|
||||
**Exemplo**
|
||||
|
||||
```js
|
||||
var array = [50,60,70];
|
||||
const array = [50, 60, 70];
|
||||
array[0];
|
||||
var data = array[1];
|
||||
const data = array[1];
|
||||
```
|
||||
|
||||
`array[0]` agora é `50` e `data` tem o 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 @@ Uma maneira de pensar em um array <dfn>multidimensional</dfn> é como um *array
|
||||
**Exemplo**
|
||||
|
||||
```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 vimos em exemplos anteriores, objetos podem conter tanto objetos aninhados
|
||||
Aqui está um exemplo de como se acessar um array aninhado:
|
||||
|
||||
```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 @@ As subpropriedades de objetos podem ser acessadas ao encadear a notação de pon
|
||||
Aqui está um objeto aninhado:
|
||||
|
||||
```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 @@ No entanto, você ainda pode usar a notação de colchetes nas propriedades dos
|
||||
Aqui está um exemplo usando a notação de colchetes para ler uma propriedade de um 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 @@ Notação de ponto é o que você utiliza quando você sabe o nome da propriedad
|
||||
Aqui está um exemplo usando notação de ponto (`.`) para ler uma propriedade do 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` teria o valor `val1` e `prop2val` teria o valor `val2`.
|
||||
|
||||
# --instructions--
|
||||
|
||||
Leia os valores de propriedade de `testObj` usando a notação de ponto. Defina a variável `hatValue` igual à propriedade `hat` do objeto e defina a variável `shirtValue` igual à propriedade `shirt` do 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 @@ Outro uso de notação de colchetes em objetos é para acessar a propriedade a q
|
||||
Aqui está um exemplo de usar uma variável para acessar uma propriedade:
|
||||
|
||||
```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 @@ A string `Doberman` seria exibida no console.
|
||||
Outra forma de você usar esse conceito é quando o nome da propriedade é coletado dinamicamente, durante a execução do programa, da seguinte forma:
|
||||
|
||||
```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 @@ Agora, quando acessamos `ourDog.bark`, nós teremos o seu latido, `bow-wow`.
|
||||
Exemplo:
|
||||
|
||||
```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 o símbolo `+` como um operador de adição quando colocado e
|
||||
**Exemplo:**
|
||||
|
||||
```js
|
||||
myVar = 5 + 10;
|
||||
const myVar = 5 + 10;
|
||||
```
|
||||
|
||||
`myVar` agora tem o valor de `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 @@ Assim como podemos construir uma string em várias linhas através das strings <
|
||||
Exemplo:
|
||||
|
||||
```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 @@ Objetos são úteis para armazenar dados de forma estruturada e podem representa
|
||||
Aqui está um exemplo de objeto gato:
|
||||
|
||||
```js
|
||||
var cat = {
|
||||
const cat = {
|
||||
"name": "Whiskers",
|
||||
"legs": 4,
|
||||
"tails": 1,
|
||||
@ -29,7 +29,7 @@ var cat = {
|
||||
Neste exemplo, todas as propriedades são armazenadas como strings, como `name`, `legs` e `tails`. Porém, você também pode usar números como propriedades. Você pode até omitir as aspas para propriedades de string com uma única palavra, da seguinte forma:
|
||||
|
||||
```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 @@ O operador mais básico é o operador de igualdade `==`. O operador de igualdade
|
||||
```js
|
||||
function equalityTest(myVal) {
|
||||
if (myVal == 10) {
|
||||
return "Equal";
|
||||
return "Equal";
|
||||
}
|
||||
return "Not Equal";
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ para adicionar `5` a `myVar`. Como este é um padrão tão comum, existem operad
|
||||
Um desses operadores é o operador `+=`.
|
||||
|
||||
```js
|
||||
var myVar = 1;
|
||||
let myVar = 1;
|
||||
myVar += 5;
|
||||
console.log(myVar);
|
||||
```
|
||||
@ -61,9 +61,9 @@ Você não deve modificar o código acima do comentário 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 @@ Você não deve modificar o código acima do comentário 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 @@ Você não deve modificar o código acima do comentário 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 @@ Você não deve modificar o código acima do comentário 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 @@ Também podemos usar o operador `+=` para <dfn>concatenar</dfn> uma string no fi
|
||||
Exemplo:
|
||||
|
||||
```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 @@ dashedName: constructing-strings-with-variables
|
||||
Exemplo:
|
||||
|
||||
```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` teria o valor da string `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));
|
||||
Você não deve alterar o código acima do comentário 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;
|
||||
Exemplo:
|
||||
|
||||
```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 usa o símbolo `/` para divisão.
|
||||
**Exemplo**
|
||||
|
||||
```js
|
||||
myVar = 16 / 2;
|
||||
const myVar = 16 / 2;
|
||||
```
|
||||
|
||||
`myVar` agora possui o 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 @@ Quando você estiver definindo uma sequência de caracteres você deve iniciar e
|
||||
Em JavaScript, você pode <dfn>escapar</dfn> uma aspa para que não seja considerada como o fim de uma string ao colocar a <dfn>barra invertida</dfn> (`\`) na frente da aspa.
|
||||
|
||||
```js
|
||||
var sampleStr = "Alan said, \"Peter is learning JavaScript\".";
|
||||
const sampleStr = "Alan said, \"Peter is learning JavaScript\".";
|
||||
```
|
||||
|
||||
Isso sinaliza ao JavaScript que a aspa seguinte não é o fim de uma string, mas que deve aparecer dentro da string. Então, se você fosse imprimir isso no console, você obteria:
|
||||
@ -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 @@ Define o `resto` igual ao restante de `11` dividido por `3` usando o operador de
|
||||
A variável `remainder` deve ser inicializada
|
||||
|
||||
```js
|
||||
assert(/var\s+?remainder/.test(code));
|
||||
assert(/(const|let|var)\s+?remainder/.test(code));
|
||||
```
|
||||
|
||||
O valor de `remainder` deve 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 @@ dashedName: global-vs--local-scope-in-functions
|
||||
Neste exemplo:
|
||||
|
||||
```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 @@ Você não deve usar o operador de atribuição.
|
||||
|
||||
```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));
|
||||
Você não deve alterar o código acima do comentário 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');
|
||||
Você não deve alterar o código acima ou abaixo dos comentários 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
|
||||
Uma tarefa comum em JavaScript é para iterar através do conteúdo de um array. Uma forma de fazer isso é com um laço `for`. Esse código vai exibir cada elemento do array `arr` no console:
|
||||
|
||||
```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
|
||||
O próximo tipo de laço que você aprenderá é chamado de laço `do...while`. O laço `do...while` é chamado assim porque primeiro fará algo (`do`) ou executará algo uma vez dentro do bloco de código, não importando o que acontecer. Em seguida, continuará a executar o laço enquanto (`while`) a condição for `true`.
|
||||
|
||||
```js
|
||||
var ourArray = [];
|
||||
var i = 0;
|
||||
const ourArray = [];
|
||||
let i = 0;
|
||||
|
||||
do {
|
||||
ourArray.push(i);
|
||||
i++;
|
||||
@ -23,8 +24,9 @@ do {
|
||||
O exemplo acima se comporta de forma similar a outros tipos de laços, e o array resultante se parecerá com `[0,1,2,3,4]`. No entanto, o que torna o laço `do...while` diferente de outros laços é como ele se comporta quando uma condição falha na primeira verificação. Vamos ver isso na prática: Aqui está um laço comum `while` que rodará o código no laço enquanto `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) {
|
||||
Nesse exemplo, inicializamos o valor de `ourArray` como um array vazio e o valor de `i` sendo 5. Quando executamos o laço `while`, a condição é igual a `false` porque `i` não é menor que 5, portanto nós não executamos o código dentro do laço. O resultado é que `ourArray` terminará sem valores adicionados a ele, e ainda se parecerá com `[]` quando todas as linhas do código no exemplo acima forem completamente executadas. Agora, dê uma olhada no laço `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 @@ Aqui está uma função `myTest` com uma variável local chamada `loc`.
|
||||
|
||||
```js
|
||||
function myTest() {
|
||||
var loc = "foo";
|
||||
const loc = "foo";
|
||||
console.log(loc);
|
||||
}
|
||||
|
||||
myTest();
|
||||
console.log(loc);
|
||||
```
|
||||
@ -38,6 +39,7 @@ O código não deve conter uma variável 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 @@ Uma forma fácil de adicionar dados no final de um array é através da função
|
||||
Exemplos:
|
||||
|
||||
```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 @@ dashedName: manipulating-complex-objects
|
||||
Aqui está um exemplo de estrutura de dados complexas:
|
||||
|
||||
```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
|
||||
Se a instrução `break` for omitida de uma instrução `case` de um `switch`, as instruções `case` seguintes serão executadas até que seja encontrado um `break`. Se você tem várias entradas com a mesma saída, você pode representá-las em uma instrução `switch` da seguinte forma:
|
||||
|
||||
```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 usa o símbolo `*` para multiplicação de dois números.
|
||||
**Exemplo**
|
||||
|
||||
```js
|
||||
myVar = 13 * 13;
|
||||
const myVar = 13 * 13;
|
||||
```
|
||||
|
||||
`myVar` teria o 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
|
||||
Você também pode aninhar arrays dentro de outros arrays, como abaixo:
|
||||
|
||||
```js
|
||||
[["Bulls", 23], ["White Sox", 45]]
|
||||
const teams = [["Bulls", 23], ["White Sox", 45]];
|
||||
```
|
||||
|
||||
Isso é chamado um <dfn>array 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
|
||||
Valores de <dfn>string</dfn> em JavaScript podem ser escritas com aspas simples ou duplas, desde que você comece e termine com o mesmo tipo de aspas. Diferente de outras linguagens de programação, aspas simples e duplas funcionam da mesma forma em 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';
|
||||
```
|
||||
|
||||
O motivo pelo qual você pode querer usar um tipo de aspas no lugar da outra é se você vir a querer usar ambas em uma string. Isso pode acontecer se você quiser salvar uma conversa em uma string e ter a conversa entre aspas. Outro uso para isso seria salvar uma tag `<a>` com vários atributos em aspas, tudo dentro de uma string.
|
||||
|
||||
```js
|
||||
conversation = 'Finn exclaims to Jake, "Algebraic!"';
|
||||
const conversation = 'Finn exclaims to Jake, "Algebraic!"';
|
||||
```
|
||||
|
||||
Porém, isso se torna um problema se você precisar usar as aspas mais extremas dentro dela. Lembre-se, uma string tem o mesmo tipo de aspas no início e no final. Mas se você tem aquela mesma aspa em algum lugar no meio, a string vai terminar mais cedo e lançará um erro.
|
||||
|
||||
```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!"';
|
||||
```
|
||||
|
||||
Aqui `badStr` lançará um erro.
|
||||
@ -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 @@ Recursão é o conceito de que uma função pode ser chamada por ela mesma. Para
|
||||
|
||||
```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 @@ Nós podemos passar valores para uma função com <dfn>argumentos</dfn>. Você p
|
||||
function plusThree(num) {
|
||||
return num + 3;
|
||||
}
|
||||
var answer = plusThree(5);
|
||||
|
||||
const answer = plusThree(5);
|
||||
```
|
||||
|
||||
`answer` tem o valor de `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 @@ Com as variáveis de `array` em JavaScript, podemos armazenar diversos dados em
|
||||
Você começa uma declaração de um array com a abertura de um colchetes, terminando com o fechamento do colchetes e colocando vírgulas entre cada entrada, dessa 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 usa o símbolo `-` para subtração.
|
||||
**Exemplo**
|
||||
|
||||
```js
|
||||
myVar = 12 - 6;
|
||||
const myVar = 12 - 6;
|
||||
```
|
||||
|
||||
`myVar` teria o 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 @@ dashedName: testing-objects-for-properties
|
||||
**Exemplo**
|
||||
|
||||
```js
|
||||
var myObj = {
|
||||
const myObj = {
|
||||
top: "hat",
|
||||
bottom: "pants"
|
||||
};
|
||||
|
||||
myObj.hasOwnProperty("top");
|
||||
myObj.hasOwnProperty("middle");
|
||||
```
|
||||
|
@ -14,14 +14,14 @@ Em JavaScript, valores `String` são <dfn>imutáveis</dfn>, o que significa que
|
||||
Por exemplo, o código a seguir:
|
||||
|
||||
```js
|
||||
var myStr = "Bob";
|
||||
let myStr = "Bob";
|
||||
myStr[0] = "J";
|
||||
```
|
||||
|
||||
não permite alterar o valor de `myStr` para `Job`, porque o conteúdo de `myStr` não pode ser alterado. Note que isso *não* significa que `myStr` não pode ser alterado, apenas que os caracteres individuais de uma <dfn>string literal</dfn> não podem ser alterados. A única forma de alterar `myStr` seria atribuindo a ela uma nova string, dessa forma:
|
||||
|
||||
```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 @@ Uma função pode incluir a instrução `return` mas ela não precisa fazer isso
|
||||
**Exemplo**
|
||||
|
||||
```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 @@ Depois de criar um objeto JavaScript, você pode atualizar suas propriedades a q
|
||||
Por exemplo, vamos dar uma olhada em `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 @@ Lembre-se de que computadores começam contando do `0`. Então, o primeiro carac
|
||||
Exemplo:
|
||||
|
||||
```js
|
||||
var firstName = "Ada";
|
||||
var secondLetterOfFirstName = firstName[1];
|
||||
const firstName = "Ada";
|
||||
const secondLetterOfFirstName = firstName[1];
|
||||
```
|
||||
|
||||
`secondLetterOfFirstName` teria o valor da string `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);
|
||||
Exemplo:
|
||||
|
||||
```js
|
||||
var a = parseInt("11", 2);
|
||||
const a = parseInt("11", 2);
|
||||
```
|
||||
|
||||
A variável radix diz que `11` está no sistema binário, ou base 2. Esse exemplo converte a string `11` para um inteiro `3`.
|
||||
|
@ -12,7 +12,7 @@ dashedName: use-the-parseint-function
|
||||
A função `parseInt()` analisa uma string e retorna um inteiro. Exemplo:
|
||||
|
||||
```js
|
||||
var a = parseInt("007");
|
||||
const a = parseInt("007");
|
||||
```
|
||||
|
||||
A função acima converte a string `007` para o inteiro `7`. Se o primeiro caractere na string não pode ser convertido em um número, então ele retorna `NaN`.
|
||||
|
@ -14,7 +14,7 @@ Objetos podem ser pensados como armazenamento de chave/valor, como um dicionári
|
||||
Aqui está um exemplo de uma simples pesquisa reversa no alfabeto:
|
||||
|
||||
```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 @@ Em um jogo de "Mad Libs", você recebe frases com algumas palavras faltando, com
|
||||
Considere a frase - Era realmente **\_\_\_\_** e nós **\_\_\_\_** nós mesmos **\_\_\_\_**. Essa frase possui três pedaços faltando - um adjetivo, um verbo e um advérbio, e nós podemos adicionar palavras de nossa escolha para completar. Em seguida, podemos atribuir a frase completa para uma variável como se segue:
|
||||
|
||||
```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.";
|
||||
```
|
||||
|
@ -13,7 +13,7 @@ Programação funcional é basicamente criar e utilizar funções que não modif
|
||||
O último desafio mostrou como usar o método `concat` para criar um novo array a partir da combinação de outros sem modificar os originais. Compare os métodos `concat` e `push`. O `push` adiciona um item ao final do array à esquerda do `.`. Ele modifica o array. Exemplo:
|
||||
|
||||
```js
|
||||
var arr = [1, 2, 3];
|
||||
const arr = [1, 2, 3];
|
||||
arr.push([4, 5, 6]);
|
||||
```
|
||||
|
||||
@ -71,8 +71,9 @@ function nonMutatingPush(original, newItem) {
|
||||
|
||||
// Only change code above this line
|
||||
}
|
||||
var first = [1, 2, 3];
|
||||
var second = [4, 5];
|
||||
|
||||
const first = [1, 2, 3];
|
||||
const second = [4, 5];
|
||||
nonMutatingPush(first, second);
|
||||
```
|
||||
|
||||
@ -82,7 +83,6 @@ nonMutatingPush(first, second);
|
||||
function nonMutatingPush(original, newItem) {
|
||||
return original.concat(newItem);
|
||||
}
|
||||
var first = [1, 2, 3];
|
||||
var second = [4, 5];
|
||||
nonMutatingPush(first, second);
|
||||
const first = [1, 2, 3];
|
||||
const second = [4, 5];
|
||||
```
|
||||
|
@ -77,7 +77,6 @@ function urlSlug(title) {
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
// Only change code below this line
|
||||
function urlSlug(title) {
|
||||
return title.trim().split(/\s+/).join("-").toLowerCase();
|
||||
}
|
||||
|
@ -57,9 +57,9 @@ A função `incrementer` deve retornar um valor baseado no valor da variável gl
|
||||
|
||||
```js
|
||||
// The global variable
|
||||
var fixedValue = 4;
|
||||
let fixedValue = 4;
|
||||
|
||||
function incrementer () {
|
||||
function incrementer() {
|
||||
// Only change code below this line
|
||||
|
||||
|
||||
@ -70,7 +70,7 @@ function incrementer () {
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var fixedValue = 4
|
||||
let fixedValue = 4
|
||||
|
||||
function incrementer() {
|
||||
return fixedValue + 1
|
||||
|
@ -13,8 +13,8 @@ O método `join` é usado para juntar os elementos de um array, resultando em um
|
||||
Exemplo:
|
||||
|
||||
```js
|
||||
var arr = ["Hello", "World"];
|
||||
var str = arr.join(" ");
|
||||
const arr = ["Hello", "World"];
|
||||
const str = arr.join(" ");
|
||||
```
|
||||
|
||||
O valor de `str` é `Hello World`.
|
||||
@ -76,6 +76,7 @@ function sentensify(str) {
|
||||
|
||||
// Only change code above this line
|
||||
}
|
||||
|
||||
sentensify("May-the-force-be-with-you");
|
||||
```
|
||||
|
||||
@ -83,8 +84,6 @@ sentensify("May-the-force-be-with-you");
|
||||
|
||||
```js
|
||||
function sentensify(str) {
|
||||
// Only change code below this line
|
||||
return str.split(/\W/).join(' ');
|
||||
// Only change code above this line
|
||||
}
|
||||
```
|
||||
|
@ -60,8 +60,9 @@ function nonMutatingConcat(original, attach) {
|
||||
|
||||
// Only change code above this line
|
||||
}
|
||||
var first = [1, 2, 3];
|
||||
var second = [4, 5];
|
||||
|
||||
const first = [1, 2, 3];
|
||||
const second = [4, 5];
|
||||
nonMutatingConcat(first, second);
|
||||
```
|
||||
|
||||
@ -69,11 +70,8 @@ nonMutatingConcat(first, second);
|
||||
|
||||
```js
|
||||
function nonMutatingConcat(original, attach) {
|
||||
// Only change code below this line
|
||||
return original.concat(attach);
|
||||
// Only change code above this line
|
||||
}
|
||||
var first = [1, 2, 3];
|
||||
var second = [4, 5];
|
||||
nonMutatingConcat(first, second);
|
||||
const first = [1, 2, 3];
|
||||
const second = [4, 5];
|
||||
```
|
||||
|
@ -38,17 +38,17 @@ assert(!code.match(/\.?[\s\S]*?map/g));
|
||||
|
||||
```js
|
||||
// The global variable
|
||||
var s = [23, 65, 98, 5];
|
||||
const s = [23, 65, 98, 5];
|
||||
|
||||
Array.prototype.myMap = function(callback) {
|
||||
var newArray = [];
|
||||
const newArray = [];
|
||||
// Only change code below this line
|
||||
|
||||
// Only change code above this line
|
||||
return newArray;
|
||||
};
|
||||
|
||||
var new_s = s.myMap(function(item) {
|
||||
const new_s = s.myMap(function(item) {
|
||||
return item * 2;
|
||||
});
|
||||
```
|
||||
@ -56,20 +56,17 @@ var new_s = s.myMap(function(item) {
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
// the global Array
|
||||
var s = [23, 65, 98, 5];
|
||||
const s = [23, 65, 98, 5];
|
||||
|
||||
Array.prototype.myMap = function(callback) {
|
||||
var newArray = [];
|
||||
// Only change code below this line
|
||||
for (var elem of this) {
|
||||
const newArray = [];
|
||||
for (const elem of this) {
|
||||
newArray.push(callback(elem));
|
||||
}
|
||||
// Only change code above this line
|
||||
return newArray;
|
||||
};
|
||||
|
||||
var new_s = s.myMap(function(item) {
|
||||
const new_s = s.myMap(function(item) {
|
||||
return item * 2;
|
||||
});
|
||||
```
|
||||
|
@ -34,16 +34,16 @@ assert(!code.match(/\.?[\s\S]*?filter/g));
|
||||
|
||||
```js
|
||||
// The global variable
|
||||
var s = [23, 65, 98, 5];
|
||||
const s = [23, 65, 98, 5];
|
||||
|
||||
Array.prototype.myFilter = function(callback) {
|
||||
// Only change code below this line
|
||||
var newArray = [];
|
||||
const newArray = [];
|
||||
// Only change code above this line
|
||||
return newArray;
|
||||
};
|
||||
|
||||
var new_s = s.myFilter(function(item) {
|
||||
const new_s = s.myFilter(function(item) {
|
||||
return item % 2 === 1;
|
||||
});
|
||||
```
|
||||
@ -51,20 +51,17 @@ var new_s = s.myFilter(function(item) {
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
// the global Array
|
||||
var s = [23, 65, 98, 5];
|
||||
const s = [23, 65, 98, 5];
|
||||
|
||||
Array.prototype.myFilter = function(callback) {
|
||||
var newArray = [];
|
||||
// Only change code below this line
|
||||
const newArray = [];
|
||||
for (let i = 0; i < this.length; i++) {
|
||||
if (callback(this[i])) newArray.push(this[i]);
|
||||
}
|
||||
// Only change code above this line
|
||||
return newArray;
|
||||
};
|
||||
|
||||
var new_s = s.myFilter(function(item) {
|
||||
const new_s = s.myFilter(function(item) {
|
||||
return item % 2 === 1;
|
||||
});
|
||||
```
|
||||
|
@ -35,7 +35,7 @@ curried(1)(2)
|
||||
Isso é útil em seu programa quando você não pode fornecer todos os argumentos para uma função de uma só vez. Você pode salvar cada chamada de função em uma variável, que será uma referência à função retornada que recebe o próximo argumento quando ele estiver disponível. Um exemplo usando a função do exemplo acima:
|
||||
|
||||
```js
|
||||
var funcForY = curried(1);
|
||||
const funcForY = curried(1);
|
||||
console.log(funcForY(2)); // 3
|
||||
```
|
||||
|
||||
@ -45,7 +45,8 @@ Da mesma forma, <dfn>aplicação parcial</dfn> pode ser descrita como a aplicaç
|
||||
function impartial(x, y, z) {
|
||||
return x + y + z;
|
||||
}
|
||||
var partialFn = impartial.bind(this, 1, 2);
|
||||
|
||||
const partialFn = impartial.bind(this, 1, 2);
|
||||
partialFn(10); // 13
|
||||
```
|
||||
|
||||
@ -90,6 +91,7 @@ function add(x) {
|
||||
|
||||
// Only change code above this line
|
||||
}
|
||||
|
||||
add(10)(20)(30);
|
||||
```
|
||||
|
||||
|
@ -53,10 +53,10 @@ assert(__newValue === 5);
|
||||
|
||||
```js
|
||||
// The global variable
|
||||
var fixedValue = 4;
|
||||
let fixedValue = 4;
|
||||
|
||||
// Only change code below this line
|
||||
function incrementer () {
|
||||
function incrementer() {
|
||||
|
||||
|
||||
// Only change code above this line
|
||||
@ -66,15 +66,9 @@ function incrementer () {
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
// The global variable
|
||||
var fixedValue = 4;
|
||||
let fixedValue = 4;
|
||||
|
||||
// Only change code below this line
|
||||
function incrementer (fixedValue) {
|
||||
function incrementer(fixedValue) {
|
||||
return fixedValue + 1;
|
||||
|
||||
// Only change code above this line
|
||||
}
|
||||
|
||||
|
||||
```
|
||||
|
@ -11,7 +11,7 @@ dashedName: remove-elements-from-an-array-using-slice-instead-of-splice
|
||||
É comum precisar remover alguns itens de um array e manter o resto. O JavaScript oferece o método `splice`, que recebe uma posição de onde começar a remover e o número de elementos para remover como argumentos para isso. Se o segundo argumento for omitido, o padrão é remover todos os itens até o final. No entanto, o método `splice` modifica o array original em que é chamado. Exemplo:
|
||||
|
||||
```js
|
||||
var cities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"];
|
||||
const cities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"];
|
||||
cities.splice(3, 1);
|
||||
```
|
||||
|
||||
@ -69,7 +69,8 @@ function nonMutatingSplice(cities) {
|
||||
|
||||
// Only change code above this line
|
||||
}
|
||||
var inputCities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"];
|
||||
|
||||
const inputCities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"];
|
||||
nonMutatingSplice(inputCities);
|
||||
```
|
||||
|
||||
@ -77,10 +78,7 @@ nonMutatingSplice(inputCities);
|
||||
|
||||
```js
|
||||
function nonMutatingSplice(cities) {
|
||||
// Only change code below this line
|
||||
return cities.slice(0,3);
|
||||
// Only change code above this line
|
||||
}
|
||||
var inputCities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"];
|
||||
nonMutatingSplice(inputCities);
|
||||
const inputCities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"];
|
||||
```
|
||||
|
@ -68,24 +68,23 @@ assert(JSON.stringify(nonMutatingSort([140000, 104, 99])) ===
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
var globalArray = [5, 6, 3, 2, 9];
|
||||
const globalArray = [5, 6, 3, 2, 9];
|
||||
|
||||
function nonMutatingSort(arr) {
|
||||
// Only change code below this line
|
||||
|
||||
|
||||
// Only change code above this line
|
||||
}
|
||||
|
||||
nonMutatingSort(globalArray);
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var globalArray = [5, 6, 3, 2, 9];
|
||||
const globalArray = [5, 6, 3, 2, 9];
|
||||
function nonMutatingSort(arr) {
|
||||
// Only change code below this line
|
||||
return [].concat(arr).sort((a,b) => a-b);
|
||||
// Only change code above this line
|
||||
}
|
||||
nonMutatingSort(globalArray);
|
||||
```
|
||||
|
@ -13,8 +13,8 @@ O método `slice` retorna uma fatia de elementos de um array. Ele pode receber d
|
||||
Exemplo:
|
||||
|
||||
```js
|
||||
var arr = ["Cat", "Dog", "Tiger", "Zebra"];
|
||||
var newArray = arr.slice(1, 3);
|
||||
const arr = ["Cat", "Dog", "Tiger", "Zebra"];
|
||||
const newArray = arr.slice(1, 3);
|
||||
```
|
||||
|
||||
`newArray` terá o valor `["Dog", "Tiger"]`.
|
||||
@ -78,7 +78,8 @@ function sliceArray(anim, beginSlice, endSlice) {
|
||||
|
||||
// Only change code above this line
|
||||
}
|
||||
var inputAnim = ["Cat", "Dog", "Tiger", "Zebra", "Ant"];
|
||||
|
||||
const inputAnim = ["Cat", "Dog", "Tiger", "Zebra", "Ant"];
|
||||
sliceArray(inputAnim, 1, 3);
|
||||
```
|
||||
|
||||
@ -86,10 +87,7 @@ sliceArray(inputAnim, 1, 3);
|
||||
|
||||
```js
|
||||
function sliceArray(anim, beginSlice, endSlice) {
|
||||
// Only change code below this line
|
||||
return anim.slice(beginSlice, endSlice)
|
||||
// Only change code above this line
|
||||
return anim.slice(beginSlice, endSlice);
|
||||
}
|
||||
var inputAnim = ["Cat", "Dog", "Tiger", "Zebra", "Ant"];
|
||||
sliceArray(inputAnim, 1, 3);
|
||||
const inputAnim = ["Cat", "Dog", "Tiger", "Zebra", "Ant"];
|
||||
```
|
||||
|
@ -18,6 +18,7 @@ function ascendingOrder(arr) {
|
||||
return a - b;
|
||||
});
|
||||
}
|
||||
|
||||
ascendingOrder([1, 5, 2, 3, 4]);
|
||||
```
|
||||
|
||||
@ -29,6 +30,7 @@ function reverseAlpha(arr) {
|
||||
return a === b ? 0 : a < b ? 1 : -1;
|
||||
});
|
||||
}
|
||||
|
||||
reverseAlpha(['l', 'h', 'z', 'b', 's']);
|
||||
```
|
||||
|
||||
@ -86,6 +88,7 @@ function alphabeticalOrder(arr) {
|
||||
return arr
|
||||
// Only change code above this line
|
||||
}
|
||||
|
||||
alphabeticalOrder(["a", "d", "c", "a", "z", "g"]);
|
||||
```
|
||||
|
||||
@ -93,9 +96,6 @@ alphabeticalOrder(["a", "d", "c", "a", "z", "g"]);
|
||||
|
||||
```js
|
||||
function alphabeticalOrder(arr) {
|
||||
// Only change code below this line
|
||||
return arr.sort();
|
||||
// Only change code above this line
|
||||
}
|
||||
alphabeticalOrder(["a", "d", "c", "a", "z", "g"]);
|
||||
```
|
||||
|
@ -13,11 +13,11 @@ O método `split` divide uma string em um array de strings. Ela recebe um delimi
|
||||
Abaixo há dois exemplos de uso de split, um separando uma string por espaços, e outro por dígitos usando uma expressão regular:
|
||||
|
||||
```js
|
||||
var str = "Hello World";
|
||||
var bySpace = str.split(" ");
|
||||
const str = "Hello World";
|
||||
const bySpace = str.split(" ");
|
||||
|
||||
var otherString = "How9are7you2today";
|
||||
var byDigits = otherString.split(/\d/);
|
||||
const otherString = "How9are7you2today";
|
||||
const byDigits = otherString.split(/\d/);
|
||||
```
|
||||
|
||||
`bySpace` terá o valor `["Hello", "World"]` e `byDigits` terá o valor `["How", "are", "you", "today"]`.
|
||||
@ -74,6 +74,7 @@ function splitify(str) {
|
||||
|
||||
// Only change code above this line
|
||||
}
|
||||
|
||||
splitify("Hello World,I-am code");
|
||||
```
|
||||
|
||||
@ -81,8 +82,6 @@ splitify("Hello World,I-am code");
|
||||
|
||||
```js
|
||||
function splitify(str) {
|
||||
// Only change code below this line
|
||||
return str.split(/\W/);
|
||||
// Only change code above this line
|
||||
}
|
||||
```
|
||||
|
@ -59,29 +59,29 @@ assert.deepEqual(finalTabs.tabs, [
|
||||
|
||||
```js
|
||||
// tabs is an array of titles of each site open within the window
|
||||
var Window = function(tabs) {
|
||||
const Window = function(tabs) {
|
||||
this.tabs = tabs; // We keep a record of the array inside the object
|
||||
};
|
||||
|
||||
// When you join two windows into one window
|
||||
Window.prototype.join = function (otherWindow) {
|
||||
Window.prototype.join = function(otherWindow) {
|
||||
this.tabs = this.tabs.concat(otherWindow.tabs);
|
||||
return this;
|
||||
};
|
||||
|
||||
// When you open a new tab at the end
|
||||
Window.prototype.tabOpen = function (tab) {
|
||||
Window.prototype.tabOpen = function(tab) {
|
||||
this.tabs.push('new tab'); // Let's open a new tab for now
|
||||
return this;
|
||||
};
|
||||
|
||||
// When you close a tab
|
||||
Window.prototype.tabClose = function (index) {
|
||||
Window.prototype.tabClose = function(index) {
|
||||
|
||||
// Only change code below this line
|
||||
|
||||
var tabsBeforeIndex = this.tabs.splice(0, index); // Get the tabs before the tab
|
||||
var tabsAfterIndex = this.tabs.splice(index + 1); // Get the tabs after the tab
|
||||
const tabsBeforeIndex = this.tabs.splice(0, index); // Get the tabs before the tab
|
||||
const tabsAfterIndex = this.tabs.splice(index + 1); // Get the tabs after the tab
|
||||
|
||||
this.tabs = tabsBeforeIndex.concat(tabsAfterIndex); // Join them together
|
||||
|
||||
@ -91,12 +91,12 @@ Window.prototype.tabClose = function (index) {
|
||||
};
|
||||
|
||||
// Let's create three browser windows
|
||||
var workWindow = new Window(['GMail', 'Inbox', 'Work mail', 'Docs', 'freeCodeCamp']); // Your mailbox, drive, and other work sites
|
||||
var socialWindow = new Window(['FB', 'Gitter', 'Reddit', 'Twitter', 'Medium']); // Social sites
|
||||
var videoWindow = new Window(['Netflix', 'YouTube', 'Vimeo', 'Vine']); // Entertainment sites
|
||||
const workWindow = new Window(['GMail', 'Inbox', 'Work mail', 'Docs', 'freeCodeCamp']); // Your mailbox, drive, and other work sites
|
||||
const socialWindow = new Window(['FB', 'Gitter', 'Reddit', 'Twitter', 'Medium']); // Social sites
|
||||
const videoWindow = new Window(['Netflix', 'YouTube', 'Vimeo', 'Vine']); // Entertainment sites
|
||||
|
||||
// Now perform the tab opening, closing, and other operations
|
||||
var finalTabs = socialWindow
|
||||
const finalTabs = socialWindow
|
||||
.tabOpen() // Open a new tab for cat memes
|
||||
.join(videoWindow.tabClose(2)) // Close third tab in video window, and join
|
||||
.join(workWindow.tabClose(1).tabOpen());
|
||||
@ -106,40 +106,34 @@ console.log(finalTabs.tabs);
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
// tabs is an array of titles of each site open within the window
|
||||
var Window = function(tabs) {
|
||||
this.tabs = tabs; // We keep a record of the array inside the object
|
||||
const Window = function(tabs) {
|
||||
this.tabs = tabs;
|
||||
};
|
||||
|
||||
// When you join two windows into one window
|
||||
Window.prototype.join = function (otherWindow) {
|
||||
Window.prototype.join = function(otherWindow) {
|
||||
this.tabs = this.tabs.concat(otherWindow.tabs);
|
||||
return this;
|
||||
};
|
||||
|
||||
// When you open a new tab at the end
|
||||
Window.prototype.tabOpen = function (tab) {
|
||||
this.tabs.push('new tab'); // Let's open a new tab for now
|
||||
Window.prototype.tabOpen = function(tab) {
|
||||
this.tabs.push('new tab');
|
||||
return this;
|
||||
};
|
||||
|
||||
// When you close a tab
|
||||
Window.prototype.tabClose = function (index) {
|
||||
var tabsBeforeIndex = this.tabs.slice(0, index); // Get the tabs before the tab
|
||||
var tabsAfterIndex = this.tabs.slice(index + 1); // Get the tabs after the tab
|
||||
Window.prototype.tabClose = function(index) {
|
||||
const tabsBeforeIndex = this.tabs.slice(0, index);
|
||||
const tabsAfterIndex = this.tabs.slice(index + 1);
|
||||
|
||||
this.tabs = tabsBeforeIndex.concat(tabsAfterIndex); // Join them together
|
||||
this.tabs = tabsBeforeIndex.concat(tabsAfterIndex);
|
||||
return this;
|
||||
};
|
||||
|
||||
// Let's create three browser windows
|
||||
var workWindow = new Window(['GMail', 'Inbox', 'Work mail', 'Docs', 'freeCodeCamp']); // Your mailbox, drive, and other work sites
|
||||
var socialWindow = new Window(['FB', 'Gitter', 'Reddit', 'Twitter', 'Medium']); // Social sites
|
||||
var videoWindow = new Window(['Netflix', 'YouTube', 'Vimeo', 'Vine']); // Entertainment sites
|
||||
const workWindow = new Window(['GMail', 'Inbox', 'Work mail', 'Docs', 'freeCodeCamp']);
|
||||
const socialWindow = new Window(['FB', 'Gitter', 'Reddit', 'Twitter', 'Medium']);
|
||||
const videoWindow = new Window(['Netflix', 'YouTube', 'Vimeo', 'Vine']);
|
||||
|
||||
// Now perform the tab opening, closing, and other operations
|
||||
var finalTabs = socialWindow
|
||||
.tabOpen() // Open a new tab for cat memes
|
||||
.join(videoWindow.tabClose(2)) // Close third tab in video window, and join
|
||||
const finalTabs = socialWindow
|
||||
.tabOpen()
|
||||
.join(videoWindow.tabClose(2))
|
||||
.join(workWindow.tabClose(1).tabOpen());
|
||||
```
|
||||
|
@ -13,7 +13,8 @@ O método `every` funciona verificando se *todos* os elementos de um array passa
|
||||
Por exemplo, o código a seguir verifica se todos os elementos no array `numbers` são menores que 10:
|
||||
|
||||
```js
|
||||
var numbers = [1, 5, 8, 0, 10, 11];
|
||||
const numbers = [1, 5, 8, 0, 10, 11];
|
||||
|
||||
numbers.every(function(currentValue) {
|
||||
return currentValue < 10;
|
||||
});
|
||||
@ -62,6 +63,7 @@ function checkPositive(arr) {
|
||||
|
||||
// Only change code above this line
|
||||
}
|
||||
|
||||
checkPositive([1, 2, 3, -4, 5]);
|
||||
```
|
||||
|
||||
@ -69,9 +71,6 @@ checkPositive([1, 2, 3, -4, 5]);
|
||||
|
||||
```js
|
||||
function checkPositive(arr) {
|
||||
// Only change code below this line
|
||||
return arr.every(num => num > 0);
|
||||
// Only change code above this line
|
||||
}
|
||||
checkPositive([1, 2, 3, -4, 5]);
|
||||
```
|
||||
|
@ -93,7 +93,7 @@ assert(getRating(watchList.filter((_, i) => i < 1 || i > 2)) === 8.55);
|
||||
|
||||
```js
|
||||
// The global variable
|
||||
var watchList = [
|
||||
const watchList = [
|
||||
{
|
||||
"Title": "Inception",
|
||||
"Year": "2010",
|
||||
@ -206,22 +206,22 @@ var watchList = [
|
||||
}
|
||||
];
|
||||
|
||||
function getRating(watchList){
|
||||
function getRating(watchList) {
|
||||
// Only change code below this line
|
||||
var averageRating;
|
||||
let averageRating;
|
||||
|
||||
|
||||
// Only change code above this line
|
||||
return averageRating;
|
||||
}
|
||||
|
||||
console.log(getRating(watchList));
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
// The global variable
|
||||
var watchList = [
|
||||
const watchList = [
|
||||
{
|
||||
"Title": "Inception",
|
||||
"Year": "2010",
|
||||
@ -334,8 +334,8 @@ var watchList = [
|
||||
}
|
||||
];
|
||||
|
||||
function getRating(watchList){
|
||||
var averageRating;
|
||||
function getRating(watchList) {
|
||||
let averageRating;
|
||||
const rating = watchList
|
||||
.filter(obj => obj.Director === "Christopher Nolan")
|
||||
.map(obj => Number(obj.imdbRating));
|
||||
|
@ -13,7 +13,8 @@ O método `some` funciona verificando se *pelo menos um* dos elementos de um arr
|
||||
Por exemplo, o código a seguir verifica se qualquer elemento no array `numbers` é menor que 10:
|
||||
|
||||
```js
|
||||
var numbers = [10, 50, 8, 220, 110, 11];
|
||||
const numbers = [10, 50, 8, 220, 110, 11];
|
||||
|
||||
numbers.some(function(currentValue) {
|
||||
return currentValue < 10;
|
||||
});
|
||||
@ -62,6 +63,7 @@ function checkPositive(arr) {
|
||||
|
||||
// Only change code above this line
|
||||
}
|
||||
|
||||
checkPositive([1, 2, 3, -4, 5]);
|
||||
```
|
||||
|
||||
@ -69,9 +71,6 @@ checkPositive([1, 2, 3, -4, 5]);
|
||||
|
||||
```js
|
||||
function checkPositive(arr) {
|
||||
// Only change code below this line
|
||||
return arr.some(elem => elem > 0);
|
||||
// Only change code above this line
|
||||
}
|
||||
checkPositive([1, 2, 3, -4, 5]);
|
||||
```
|
||||
|
@ -157,7 +157,7 @@ assert(diffArray([1, 'calf', 3, 'piglet'], [7, 'filly']).length === 6);
|
||||
|
||||
```js
|
||||
function diffArray(arr1, arr2) {
|
||||
var newArr = [];
|
||||
const newArr = [];
|
||||
return newArr;
|
||||
}
|
||||
|
||||
@ -168,13 +168,12 @@ diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]);
|
||||
|
||||
```js
|
||||
function diffArray(arr1, arr2) {
|
||||
var newArr = [];
|
||||
var h1 = Object.create(null);
|
||||
const newArr = [];
|
||||
const h1 = Object.create(null);
|
||||
arr1.forEach(function(e) {
|
||||
h1[e] = e;
|
||||
});
|
||||
|
||||
var h2 = Object.create(null);
|
||||
const h2 = Object.create(null);
|
||||
arr2.forEach(function(e) {
|
||||
h2[e] = e;
|
||||
});
|
||||
|
@ -23,10 +23,19 @@ Execute os testes para ver a saída esperada para cada método. Os métodos que
|
||||
|
||||
# --hints--
|
||||
|
||||
`Object.keys(bob).length` deve retornar 6.
|
||||
Nenhuma propriedade deve ser adicionada. `Object.keys(bob).length` deve sempre retornar 6.
|
||||
|
||||
```js
|
||||
assert.deepEqual(Object.keys(bob).length, 6);
|
||||
assert.strictEqual(
|
||||
Object.keys((function () {
|
||||
let bob = new Person('Bob Ross');
|
||||
bob.setFirstName('Haskell');
|
||||
bob.setLastName('Curry');
|
||||
bob.setFullName('John Smith');
|
||||
return bob;
|
||||
})()).length,
|
||||
6
|
||||
);
|
||||
```
|
||||
|
||||
`bob instanceof Pessoa` deve retornar `true`.
|
||||
@ -139,7 +148,7 @@ if(bob){
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
var Person = function(firstAndLast) {
|
||||
const Person = function(firstAndLast) {
|
||||
// Only change code below this line
|
||||
// Complete the method below and implement the others similarly
|
||||
this.getFullName = function() {
|
||||
@ -148,16 +157,16 @@ var Person = function(firstAndLast) {
|
||||
return firstAndLast;
|
||||
};
|
||||
|
||||
var bob = new Person('Bob Ross');
|
||||
const bob = new Person('Bob Ross');
|
||||
bob.getFullName();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var Person = function(firstAndLast) {
|
||||
const Person = function(firstAndLast) {
|
||||
|
||||
var firstName, lastName;
|
||||
let firstName, lastName;
|
||||
|
||||
function updateName(str) {
|
||||
firstName = str.split(" ")[0];
|
||||
@ -192,6 +201,6 @@ var Person = function(firstAndLast) {
|
||||
};
|
||||
};
|
||||
|
||||
var bob = new Person('Bob Ross');
|
||||
const bob = new Person('Bob Ross');
|
||||
bob.getFullName();
|
||||
```
|
||||
|
@ -51,8 +51,8 @@ assert.deepEqual(
|
||||
|
||||
```js
|
||||
function orbitalPeriod(arr) {
|
||||
var GM = 398600.4418;
|
||||
var earthRadius = 6367.4447;
|
||||
const GM = 398600.4418;
|
||||
const earthRadius = 6367.4447;
|
||||
return arr;
|
||||
}
|
||||
|
||||
@ -63,9 +63,9 @@ orbitalPeriod([{name : "sputnik", avgAlt : 35873.5553}]);
|
||||
|
||||
```js
|
||||
function orbitalPeriod(arr) {
|
||||
var GM = 398600.4418;
|
||||
var earthRadius = 6367.4447;
|
||||
var TAU = 2 * Math.PI;
|
||||
const GM = 398600.4418;
|
||||
const earthRadius = 6367.4447;
|
||||
const TAU = 2 * Math.PI;
|
||||
return arr.map(function(obj) {
|
||||
return {
|
||||
name: obj.name,
|
||||
@ -73,6 +73,4 @@ function orbitalPeriod(arr) {
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
orbitalPeriod([{name : "sputkin", avgAlt : 35873.5553}]);
|
||||
```
|
||||
|
@ -61,7 +61,6 @@ function smallestCommons(arr) {
|
||||
return arr;
|
||||
}
|
||||
|
||||
|
||||
smallestCommons([1,5]);
|
||||
```
|
||||
|
||||
|
@ -103,7 +103,7 @@ assert.deepEqual(
|
||||
|
||||
```js
|
||||
function whatIsInAName(collection, source) {
|
||||
var arr = [];
|
||||
const arr = [];
|
||||
// Only change code below this line
|
||||
|
||||
|
||||
@ -118,8 +118,8 @@ whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last:
|
||||
|
||||
```js
|
||||
function whatIsInAName(collection, source) {
|
||||
var arr = [];
|
||||
var keys = Object.keys(source);
|
||||
const arr = [];
|
||||
const keys = Object.keys(source);
|
||||
collection.forEach(function(e) {
|
||||
if(keys.every(function(key) {return e[key] === source[key];})) {
|
||||
arr.push(e);
|
||||
|
@ -51,7 +51,6 @@ assert(
|
||||
|
||||
```js
|
||||
function rot13(str) {
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
|
@ -186,7 +186,7 @@ assert.deepEqual(
|
||||
|
||||
```js
|
||||
function checkCashRegister(price, cash, cid) {
|
||||
var change;
|
||||
let change;
|
||||
return change;
|
||||
}
|
||||
|
||||
@ -196,54 +196,57 @@ checkCashRegister(19.5, 20, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], [
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
var denom = [
|
||||
{ name: 'ONE HUNDRED', val: 100},
|
||||
{ name: 'TWENTY', val: 20},
|
||||
{ name: 'TEN', val: 10},
|
||||
{ name: 'FIVE', val: 5},
|
||||
{ name: 'ONE', val: 1},
|
||||
{ name: 'QUARTER', val: 0.25},
|
||||
{ name: 'DIME', val: 0.1},
|
||||
{ name: 'NICKEL', val: 0.05},
|
||||
{ name: 'PENNY', val: 0.01}
|
||||
const denom = [
|
||||
{ name: "ONE HUNDRED", val: 100 },
|
||||
{ name: "TWENTY", val: 20 },
|
||||
{ name: "TEN", val: 10 },
|
||||
{ name: "FIVE", val: 5 },
|
||||
{ name: "ONE", val: 1 },
|
||||
{ name: "QUARTER", val: 0.25 },
|
||||
{ name: "DIME", val: 0.1 },
|
||||
{ name: "NICKEL", val: 0.05 },
|
||||
{ name: "PENNY", val: 0.01 },
|
||||
];
|
||||
|
||||
function checkCashRegister(price, cash, cid) {
|
||||
var output = {status: null, change: []};
|
||||
var change = cash - price;
|
||||
var register = cid.reduce(function(acc, curr) {
|
||||
acc.total += curr[1];
|
||||
acc[curr[0]] = curr[1];
|
||||
return acc;
|
||||
}, {total: 0});
|
||||
if(register.total === change) {
|
||||
output.status = 'CLOSED';
|
||||
output.change = cid;
|
||||
return output;
|
||||
}
|
||||
if(register.total < change) {
|
||||
output.status = 'INSUFFICIENT_FUNDS';
|
||||
return output;
|
||||
}
|
||||
var change_arr = denom.reduce(function(acc, curr) {
|
||||
var value = 0;
|
||||
while(register[curr.name] > 0 && change >= curr.val) {
|
||||
change -= curr.val;
|
||||
register[curr.name] -= curr.val;
|
||||
value += curr.val;
|
||||
change = Math.round(change * 100) / 100;
|
||||
}
|
||||
if(value > 0) {
|
||||
acc.push([ curr.name, value ]);
|
||||
}
|
||||
return acc;
|
||||
}, []);
|
||||
if(change_arr.length < 1 || change > 0) {
|
||||
output.status = 'INSUFFICIENT_FUNDS';
|
||||
return output;
|
||||
}
|
||||
output.status = 'OPEN';
|
||||
output.change = change_arr;
|
||||
return output;
|
||||
const output = { status: null, change: [] };
|
||||
let change = cash - price;
|
||||
const register = cid.reduce(
|
||||
function (acc, curr) {
|
||||
acc.total += curr[1];
|
||||
acc[curr[0]] = curr[1];
|
||||
return acc;
|
||||
},
|
||||
{ total: 0 }
|
||||
);
|
||||
if (register.total === change) {
|
||||
output.status = "CLOSED";
|
||||
output.change = cid;
|
||||
return output;
|
||||
}
|
||||
if (register.total < change) {
|
||||
output.status = "INSUFFICIENT_FUNDS";
|
||||
return output;
|
||||
}
|
||||
const change_arr = denom.reduce(function (acc, curr) {
|
||||
let value = 0;
|
||||
while (register[curr.name] > 0 && change >= curr.val) {
|
||||
change -= curr.val;
|
||||
register[curr.name] -= curr.val;
|
||||
value += curr.val;
|
||||
change = Math.round(change * 100) / 100;
|
||||
}
|
||||
if (value > 0) {
|
||||
acc.push([curr.name, value]);
|
||||
}
|
||||
return acc;
|
||||
}, []);
|
||||
if (change_arr.length < 1 || change > 0) {
|
||||
output.status = "INSUFFICIENT_FUNDS";
|
||||
return output;
|
||||
}
|
||||
output.status = "OPEN";
|
||||
output.change = change_arr;
|
||||
return output;
|
||||
}
|
||||
```
|
||||
|
@ -107,8 +107,6 @@ function palindrome(str) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
palindrome("eye");
|
||||
```
|
||||
|
||||
|
Reference in New Issue
Block a user