chore(learn): remove other language curriculum Chinese (#39745)
This commit is contained in:
@ -1,66 +0,0 @@
|
||||
---
|
||||
id: 56bbb991ad1ed5201cd392ca
|
||||
title: Access Array Data with Indexes
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Dados de Matriz de Acesso com Índices
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Podemos acessar os dados dentro de matrizes usando <code>indexes</code> . Os índices de matriz são escritos na mesma notação de colchetes usada pelas cadeias, exceto que, em vez de especificar um caractere, eles estão especificando uma entrada na matriz. Como as strings, as matrizes usam indexação <dfn>baseada em zero</dfn> , portanto, o primeiro elemento em uma matriz é o elemento <code>0</code> . <strong>Exemplo</strong> <blockquote> var array = [50,60,70]; <br> array [0]; // é igual a 50 <br> var data = array [1]; // é igual a 60 </blockquote> <strong>Nota</strong> <br> Não deve haver espaços entre o nome da matriz e os colchetes, como <code>array [0]</code> . Embora JavaScript seja capaz de processar isso corretamente, isso pode confundir outros programadores lendo seu código. </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Crie uma variável chamada <code>myData</code> e configure-a para igualar o primeiro valor de <code>myArray</code> usando a notação de colchetes. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: A variável <code>myData</code> deve ser igual ao primeiro valor de <code>myArray</code> .
|
||||
testString: 'assert((function(){if(typeof myArray !== "undefined" && typeof myData !== "undefined" && myArray[0] === myData){return true;}else{return false;}})(), "The variable <code>myData</code> should equal the first value of <code>myArray</code>.");'
|
||||
- text: Os dados na variável <code>myArray</code> devem ser acessados usando a notação de colchetes.
|
||||
testString: 'assert((function(){if(code.match(/\s*=\s*myArray\[0\]/g)){return true;}else{return false;}})(), "The data in variable <code>myArray</code> should be accessed using bracket notation.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var ourArray = [50,60,70];
|
||||
var ourData = ourArray[0]; // equals 50
|
||||
|
||||
// Setup
|
||||
var myArray = [50,60,70];
|
||||
|
||||
// Only change code below this line.
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,63 +0,0 @@
|
||||
---
|
||||
id: 56592a60ddddeae28f7aa8e1
|
||||
title: Access Multi-Dimensional Arrays With Indexes
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Acessar matrizes multi-dimensionais com índices
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Uma maneira de pensar em uma matriz <dfn>multidimensional</dfn> é como uma <em>matriz de matrizes</em> . Quando você usa colchetes para acessar sua matriz, o primeiro conjunto de colchetes refere-se às entradas na matriz mais externa (o primeiro nível) e cada par adicional de colchetes refere-se ao próximo nível de entradas internas. <strong>Exemplo</strong> <blockquote> var arr = [ <br> [1,2,3], <br> [4,5,6], <br> [7,8,9], <br> [[10,11,12], 13, 14] <br> ]; <br> arr [3]; // é igual a [[10,11,12], 13, 14] <br> arr [3] [0]; // é igual a [10,11,12] <br> arr [3] [0] [1]; // é igual a 11 </blockquote> <strong>Nota</strong> <br> Não deve haver espaços entre o nome da matriz e os colchetes, como <code>array [0][0]</code> e até mesmo esta <code>array [0] [0]</code> não é permitida. Embora JavaScript seja capaz de processar isso corretamente, isso pode confundir outros programadores lendo seu código. </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Usando a notação de colchetes, selecione um elemento em <code>myArray</code> , de forma que <code>myData</code> seja igual a <code>8</code> . </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>myData</code> deve ser igual a <code>8</code> .
|
||||
testString: 'assert(myData === 8, "<code>myData</code> should be equal to <code>8</code>.");'
|
||||
- text: Você deve estar usando a notação de colchetes para ler o valor correto de <code>myArray</code> .
|
||||
testString: 'assert(/myArray\[2\]\[1\]/g.test(code) && !/myData\s*=\s*(?:.*[-+*/%]|\d)/g.test(code), "You should be using bracket notation to read the correct value from <code>myArray</code>.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var myArray = [[1,2,3], [4,5,6], [7,8,9], [[10,11,12], 13, 14]];
|
||||
|
||||
// Only change code below this line.
|
||||
var myData = myArray[0][0];
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,81 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244cd
|
||||
title: Accessing Nested Arrays
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Acessando matrizes aninhadas
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Como vimos nos exemplos anteriores, os objetos podem conter tanto objetos aninhados quanto matrizes aninhadas. Semelhante ao acesso a objetos aninhados, a notação de colchetes da Array pode ser encadeada para acessar matrizes aninhadas. Aqui está um exemplo de como acessar uma matriz aninhada: <blockquote> var ourPets = [ <br> { <br> animalTipo: "gato", <br> nomes: [ <br> "Meowzer", <br> "Fofo", <br> "Kit-Cat" <br> ] <br> } <br> { <br> animalTipo: "cachorro", <br> nomes: [ <br> "Local", <br> "Bowser", <br> "Frankie" <br> ] <br> } <br> ]; <br> ourPets [0] .nomes [1]; // "Fofo" <br> ourPets [1] .nomes [0]; // "Local" </blockquote></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Recuperar a segunda árvore da variável <code>myPlants</code> usando ponto de objeto e notação de colchetes de matriz. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>secondTree</code> deve ser igual a "pine"
|
||||
testString: 'assert(secondTree === "pine", "<code>secondTree</code> should equal "pine"");'
|
||||
- text: Use a notação de pontos e colchetes para acessar <code>myPlants</code>
|
||||
testString: 'assert(/=\s*myPlants\[1\].list\[1\]/.test(code), "Use dot and bracket notation to access <code>myPlants</code>");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var myPlants = [
|
||||
{
|
||||
type: "flowers",
|
||||
list: [
|
||||
"rose",
|
||||
"tulip",
|
||||
"dandelion"
|
||||
]
|
||||
},
|
||||
{
|
||||
type: "trees",
|
||||
list: [
|
||||
"fir",
|
||||
"pine",
|
||||
"birch"
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
// Only change code below this line
|
||||
|
||||
var secondTree = ""; // Change this line
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,72 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244cc
|
||||
title: Accessing Nested Objects
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Acessando Objetos Aninhados
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> As subpropriedades dos objetos podem ser acessadas encadeando a notação de pontos ou colchetes. Aqui está um objeto aninhado: <blockquote> var ourStorage = { <br> "escrivaninha": { <br> "gaveta": "grampeador" <br> } <br> "gabinete": { <br> "gaveta superior": { <br> "folder1": "um arquivo", <br> "folder2": "segredos" <br> } <br> "gaveta de fundo": "refrigerante" <br> } <br> }; <br> ourStorage.cabinet ["gaveta de cima"]. folder2; // "segredos" <br> ourStorage.desk.drawer; // "agrafador" </blockquote></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Acesse o objeto <code>myStorage</code> e atribua o conteúdo da propriedade <code>glove box</code> à variável <code>gloveBoxContents</code> . Use a notação de colchetes para propriedades com um espaço em seus nomes. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>gloveBoxContents</code> deve ser igual a "mapas"
|
||||
testString: 'assert(gloveBoxContents === "maps", "<code>gloveBoxContents</code> should equal "maps"");'
|
||||
- text: Use a notação de pontos e colchetes para acessar <code>myStorage</code>
|
||||
testString: 'assert(/=\s*myStorage\.car\.inside\[\s*("|")glove box\1\s*\]/g.test(code), "Use dot and bracket notation to access <code>myStorage</code>");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var myStorage = {
|
||||
"car": {
|
||||
"inside": {
|
||||
"glove box": "maps",
|
||||
"passenger seat": "crumbs"
|
||||
},
|
||||
"outside": {
|
||||
"trunk": "jack"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var gloveBoxContents = undefined; // Change this line
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,75 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244c8
|
||||
title: Accessing Object Properties with Bracket Notation
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Acessando propriedades de objeto com notação de suporte
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> A segunda maneira de acessar as propriedades de um objeto é a notação de colchetes ( <code>[]</code> ). Se a propriedade do objeto que você está tentando acessar tiver um espaço em seu nome, você precisará usar a notação de colchetes. No entanto, você ainda pode usar a notação de colchetes nas propriedades do objeto sem espaços. Aqui está uma amostra de uso da notação de colchetes para ler a propriedade de um objeto: <blockquote> var myObj = { <br> "Space Name": "Kirk", <br> "Mais espaço": "Spock", <br> "NoSpace": "USS Enterprise" <br> }; <br> myObj ["nome do espaço"]; // Kirk <br> myObj ['More Space']; // Spock <br> myObj ["NoSpace"]; // USS Enterprise </blockquote> Observe que os nomes de propriedade com espaços neles devem estar entre aspas (simples ou dupla). </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Leia os valores das propriedades <code>"an entree"</code> e <code>"the drink"</code> de <code>testObj</code> usando a notação de colchetes e atribua-os a <code>entreeValue</code> e <code>drinkValue</code> respectivamente. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>entreeValue</code> deve ser uma string
|
||||
testString: 'assert(typeof entreeValue === "string" , "<code>entreeValue</code> should be a string");'
|
||||
- text: O valor de <code>entreeValue</code> deve ser <code>"hamburger"</code>
|
||||
testString: 'assert(entreeValue === "hamburger" , "The value of <code>entreeValue</code> should be <code>"hamburger"</code>");'
|
||||
- text: <code>drinkValue</code> deve ser uma string
|
||||
testString: 'assert(typeof drinkValue === "string" , "<code>drinkValue</code> should be a string");'
|
||||
- text: O valor de <code>drinkValue</code> deve ser <code>"water"</code>
|
||||
testString: 'assert(drinkValue === "water" , "The value of <code>drinkValue</code> should be <code>"water"</code>");'
|
||||
- text: Você deve usar a notação de colchete duas vezes
|
||||
testString: 'assert(code.match(/testObj\s*?\[("|")[^""]+\1\]/g).length > 1, "You should use bracket notation twice");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var 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
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,75 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244c7
|
||||
title: Accessing Object Properties with Dot Notation
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Acessando propriedades de objeto com notação de ponto
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Há duas maneiras de acessar as propriedades de um objeto: notação de ponto ( <code>.</code> ) E notação de colchetes ( <code>[]</code> ), semelhante a uma matriz. A notação de pontos é o que você usa quando sabe o nome da propriedade que está tentando acessar antecipadamente. Aqui está uma amostra de uso de notação de ponto ( <code>.</code> ) Para ler a propriedade de um objeto: <blockquote> var myObj = { <br> prop1: "val1", <br> prop2: "val2" <br> }; <br> var prop1val = myObj.prop1; // val1 <br> var prop2val = myObj.prop2; // val2 </blockquote></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Leia os valores de propriedade de <code>testObj</code> usando a notação de ponto. Defina a variável <code>hatValue</code> igual ao <code>hat</code> propriedade do objeto e defina a variável <code>shirtValue</code> igual à <code>shirt</code> propriedade do objeto. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>hatValue</code> deve ser uma string
|
||||
testString: 'assert(typeof hatValue === "string" , "<code>hatValue</code> should be a string");'
|
||||
- text: O valor de <code>hatValue</code> deve ser <code>"ballcap"</code>
|
||||
testString: 'assert(hatValue === "ballcap" , "The value of <code>hatValue</code> should be <code>"ballcap"</code>");'
|
||||
- text: <code>shirtValue</code> deve ser uma string
|
||||
testString: 'assert(typeof shirtValue === "string" , "<code>shirtValue</code> should be a string");'
|
||||
- text: O valor de <code>shirtValue</code> deve ser <code>"jersey"</code>
|
||||
testString: 'assert(shirtValue === "jersey" , "The value of <code>shirtValue</code> should be <code>"jersey"</code>");'
|
||||
- text: Você deve usar a notação de ponto duas vezes
|
||||
testString: 'assert(code.match(/testObj\.\w+/g).length > 1, "You should use dot notation twice");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var 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
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,77 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244c9
|
||||
title: Accessing Object Properties with Variables
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Acessando propriedades de objetos com variáveis
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Outro uso da notação de colchetes em objetos é acessar uma propriedade que é armazenada como o valor de uma variável. Isso pode ser muito útil para iterar pelas propriedades de um objeto ou ao acessar uma tabela de pesquisa. Aqui está um exemplo de uso de uma variável para acessar uma propriedade: <blockquote> var dogs = { <br> Fido: "Mutt", Hunter: "Doberman", Snoopie: "Beagle" <br> }; <br> var myDog = "Caçador"; <br> var myBreed = cachorros [myDog]; <br> console.log (myBreed); // "Doberman" </blockquote> Outra maneira de usar esse conceito é quando o nome da propriedade é coletado dinamicamente durante a execução do programa, da seguinte maneira: <blockquote> var someObj = { <br> propName: "John" <br> }; <br> function propPrefix (str) { <br> var s = "prop"; <br> return s + str; <br> } <br> var someProp = propPrefix ("Nome"); // someProp agora contém o valor 'propName' <br> console.log (someObj [someProp]); // "John" </blockquote> Observe que <em>não</em> usamos aspas ao redor do nome da variável ao usá-lo para acessar a propriedade porque estamos usando o <em>valor</em> da variável, não o <em>nome</em> . </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Use a variável <code>playerNumber</code> para procurar o player <code>16</code> em <code>testObj</code> usando a notação de colchetes. Em seguida, atribua esse nome à variável do <code>player</code> . </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>playerNumber</code> deve ser um número
|
||||
testString: 'assert(typeof playerNumber === "number", "<code>playerNumber</code> should be a number");'
|
||||
- text: O <code>player</code> variável deve ser uma string
|
||||
testString: 'assert(typeof player === "string", "The variable <code>player</code> should be a string");'
|
||||
- text: O valor do <code>player</code> deve ser "Montana"
|
||||
testString: 'assert(player === "Montana", "The value of <code>player</code> should be "Montana"");'
|
||||
- text: Você deve usar a notação de colchetes para acessar o <code>testObj</code>
|
||||
testString: 'assert(/testObj\s*?\[.*?\]/.test(code),"You should use bracket notation to access <code>testObj</code>");'
|
||||
- text: Você não deve atribuir o valor <code>Montana</code> ao <code>player</code> variável diretamente.
|
||||
testString: 'assert(!code.match(/player\s*=\s*"|\"\s*Montana\s*"|\"\s*;/gi),"You should not assign the value <code>Montana</code> to the variable <code>player</code> directly.");'
|
||||
- text: Você deve estar usando a variável <code>playerNumber</code> na sua notação de colchetes
|
||||
testString: 'assert(/testObj\s*?\[\s*playerNumber\s*\]/.test(code),"You should be using the variable <code>playerNumber</code> in your bracket notation");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var testObj = {
|
||||
12: "Namath",
|
||||
16: "Montana",
|
||||
19: "Unitas"
|
||||
};
|
||||
|
||||
// Only change code below this line;
|
||||
|
||||
var playerNumber; // Change this Line
|
||||
var player = testObj; // Change this Line
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,77 +0,0 @@
|
||||
---
|
||||
id: 56bbb991ad1ed5201cd392d2
|
||||
title: Add New Properties to a JavaScript Object
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Adicionar novas propriedades a um objeto JavaScript
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Você pode adicionar novas propriedades a objetos JavaScript existentes da mesma maneira que você os modificaria. Veja como adicionaríamos uma propriedade <code>"bark"</code> ao <code>ourDog</code> : <code>ourDog.bark = "bow-wow";</code> ou <code>ourDog["bark"] = "bow-wow";</code> Agora, quando avaliarmos o nosso <code>ourDog.bark</code> , vamos pegar o latido dele, "bow-wow". </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Adicione uma propriedade <code>"bark"</code> ao <code>myDog</code> e configure-a para um som de cachorro, como "woof". Você pode usar a notação de pontos ou colchetes. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Adicione a propriedade <code>"bark"</code> ao <code>myDog</code> .
|
||||
testString: 'assert(myDog.bark !== undefined, "Add the property <code>"bark"</code> to <code>myDog</code>.");'
|
||||
- text: Não adicione <code>"bark"</code> à seção de configuração
|
||||
testString: 'assert(!/bark[^\n]:/.test(code), "Do not add <code>"bark"</code> to the setup section");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var ourDog = {
|
||||
"name": "Camper",
|
||||
"legs": 4,
|
||||
"tails": 1,
|
||||
"friends": ["everything!"]
|
||||
};
|
||||
|
||||
ourDog.bark = "bow-wow";
|
||||
|
||||
// Setup
|
||||
var myDog = {
|
||||
"name": "Happy Coder",
|
||||
"legs": 4,
|
||||
"tails": 1,
|
||||
"friends": ["freeCodeCamp Campers"]
|
||||
};
|
||||
|
||||
// Only change code below this line.
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,59 +0,0 @@
|
||||
---
|
||||
id: cf1111c1c11feddfaeb3bdef
|
||||
title: Add Two Numbers with JavaScript
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Adicione dois números com JavaScript
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> <code>Number</code> é um tipo de dados em JavaScript que representa dados numéricos. Agora vamos tentar adicionar dois números usando JavaScript. O JavaScript usa o símbolo <code>+</code> como operação de adição quando colocado entre dois números. <strong>Exemplo</strong> <blockquote> myVar = 5 + 10; // atribuído 15 </blockquote></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Altere <code>0</code> para que a soma seja igual a <code>20</code> . </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>sum</code> deve ser igual a <code>20</code>
|
||||
testString: 'assert(sum === 20, "<code>sum</code> should equal <code>20</code>");'
|
||||
- text: Use o operador <code>+</code>
|
||||
testString: 'assert(/\+/.test(code), "Use the <code>+</code> operator");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
var sum = 10 + 0;
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,74 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244de
|
||||
title: Adding a Default Option in Switch Statements
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Adicionando uma opção padrão em instruções de troca
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Em uma instrução <code>switch</code> , você pode não conseguir especificar todos os valores possíveis como instruções <code>case</code> . Em vez disso, você pode adicionar a instrução <code>default</code> que será executada se nenhuma instrução <code>case</code> correspondente for encontrada. Pense nisso como a final <code>else</code> declaração em um <code>if/else</code> cadeia. Uma declaração <code>default</code> deve ser o último caso. <blockquote> switch (num) { <br> valor do caso1: <br> statement1; <br> pausa; <br> valor do caso2: <br> statement2; <br> pausa; <br> ... <br> padrão: <br> defaultStatement; <br> pausa; <br> } </blockquote></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Escreva uma instrução switch para definir a <code>answer</code> para as seguintes condições: <br> <code>"a"</code> - "maçã" <br> <code>"b"</code> - "pássaro" <br> <code>"c"</code> - "gato" <br> <code>default</code> - "stuff" </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>switchOfStuff("a")</code> deve ter um valor de "apple"
|
||||
testString: 'assert(switchOfStuff("a") === "apple", "<code>switchOfStuff("a")</code> should have a value of "apple"");'
|
||||
- text: <code>switchOfStuff("b")</code> deve ter um valor de "bird"
|
||||
testString: 'assert(switchOfStuff("b") === "bird", "<code>switchOfStuff("b")</code> should have a value of "bird"");'
|
||||
- text: <code>switchOfStuff("c")</code> deve ter um valor de "cat"
|
||||
testString: 'assert(switchOfStuff("c") === "cat", "<code>switchOfStuff("c")</code> should have a value of "cat"");'
|
||||
- text: <code>switchOfStuff("d")</code> deve ter um valor de "stuff"
|
||||
testString: 'assert(switchOfStuff("d") === "stuff", "<code>switchOfStuff("d")</code> should have a value of "stuff"");'
|
||||
- text: <code>switchOfStuff(4)</code> deve ter um valor de "stuff"
|
||||
testString: 'assert(switchOfStuff(4) === "stuff", "<code>switchOfStuff(4)</code> should have a value of "stuff"");'
|
||||
- text: Você não deve usar nenhuma instrução <code>if</code> ou <code>else</code>
|
||||
testString: 'assert(!/else/g.test(code) || !/if/g.test(code), "You should not use any <code>if</code> or <code>else</code> statements");'
|
||||
- text: Você deve usar uma declaração <code>default</code>
|
||||
testString: 'assert(switchOfStuff("string-to-trigger-default-case") === "stuff", "You should use a <code>default</code> statement");'
|
||||
- text: Você deve ter pelo menos 3 declarações de <code>break</code>
|
||||
testString: 'assert(code.match(/break/g).length > 2, "You should have at least 3 <code>break</code> statements");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function switchOfStuff(val) {
|
||||
var answer = "";
|
||||
// Only change code below this line
|
||||
|
||||
|
||||
|
||||
// Only change code above this line
|
||||
return answer;
|
||||
}
|
||||
|
||||
// Change this value to test
|
||||
switchOfStuff(1);
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,67 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244ed
|
||||
title: Appending Variables to Strings
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Anexando variáveis a seqüências de caracteres
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Assim como podemos construir uma string sobre várias linhas a partir de <dfn>literais</dfn> de string, também podemos anexar variáveis a uma string usando o operador mais igual ( <code>+=</code> ). </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Defina <code>someAdjective</code> e anexe-o ao <code>myStr</code> usando o operador <code>+=</code> . </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>someAdjective</code> deve ser definido para uma string com pelo menos 3 caracteres
|
||||
testString: 'assert(typeof someAdjective !== "undefined" && someAdjective.length > 2, "<code>someAdjective</code> should be set to a string at least 3 characters long");'
|
||||
- text: Anexar <code>someAdjective</code> ao <code>myStr</code> usando o operador <code>+=</code>
|
||||
testString: 'assert(code.match(/myStr\s*\+=\s*someAdjective\s*/).length > 0, "Append <code>someAdjective</code> to <code>myStr</code> using the <code>+=</code> operator");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var anAdjective = "awesome!";
|
||||
var ourStr = "freeCodeCamp is ";
|
||||
ourStr += anAdjective;
|
||||
|
||||
// Only change code below this line
|
||||
|
||||
var someAdjective;
|
||||
var myStr = "Learning to code is ";
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,75 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244c3
|
||||
title: Assignment with a Returned Value
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Atribuição com um valor retornado
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Se você se lembrar de nossa discussão sobre <a href="/learn/javascript-algorithms-and-data-structures/basic-javascript/storing-values-with-the-assignment-operator" target="_blank">Armazenando Valores com o Operador de Atribuição</a> , tudo à direita do sinal de igual será resolvido antes de o valor ser atribuído. Isso significa que podemos pegar o valor de retorno de uma função e atribuí-la a uma variável. Suponha que tenhamos pré-definido uma <code>sum</code> funções que adiciona dois números juntos, então: <code>ourSum = sum(5, 12);</code> chamará a função <code>sum</code> , que retorna um valor de <code>17</code> e atribui à variável <code>ourSum</code> . </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Chame a função <code>processArg</code> com um argumento de <code>7</code> e atribua seu valor de retorno à variável <code>processed</code> . </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>processed</code> deve ter um valor de <code>2</code>
|
||||
testString: 'assert(processed === 2, "<code>processed</code> should have a value of <code>2</code>");'
|
||||
- text: Você deve atribuir <code>processArg</code> a <code>processed</code>
|
||||
testString: 'assert(/processed\s*=\s*processArg\(\s*7\s*\)\s*;/.test(code), "You should assign <code>processArg</code> to <code>processed</code>");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var changed = 0;
|
||||
|
||||
function change(num) {
|
||||
return (num + 5) / 3;
|
||||
}
|
||||
|
||||
changed = change(10);
|
||||
|
||||
// Setup
|
||||
var processed = 0;
|
||||
|
||||
function processArg(num) {
|
||||
return (num + 3) / 5;
|
||||
}
|
||||
|
||||
// Only change code below this line
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,80 +0,0 @@
|
||||
---
|
||||
id: 56bbb991ad1ed5201cd392d0
|
||||
title: Build JavaScript Objects
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Construa objetos JavaScript
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Você pode ter ouvido o termo <code>object</code> antes. Os objetos são semelhantes aos <code>arrays</code> , exceto que, em vez de usar índices para acessar e modificar seus dados, você acessa os dados em objetos por meio do que são chamados de <code>properties</code> . Os objetos são úteis para armazenar dados de maneira estruturada e podem representar objetos do mundo real, como um gato. Aqui está um objeto cat de amostra: <blockquote> var cat = { <br> "nome": "Bigodes", <br> "pernas": 4, <br> "coroa": 1, <br> "inimigos": ["Água", "Cães"] <br> }; </blockquote> Neste exemplo, todas as propriedades são armazenadas como strings, como - <code>"name"</code> , <code>"legs"</code> e <code>"tails"</code> . No entanto, você também pode usar números como propriedades. Você pode até mesmo omitir as aspas para propriedades de string de palavra única, da seguinte maneira: <blockquote> var anotherObject = { <br> make: "Ford", <br> 5: "cinco", <br> "modelo": "foco" <br> }; </blockquote> No entanto, se o seu objeto tiver alguma propriedade que não seja de string, o JavaScript será automaticamente convertido em typecast como string. </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Crie um objeto que represente um cão chamado <code>myDog</code> que contenha as propriedades <code>"name"</code> (uma string), <code>"legs"</code> , <code>"tails"</code> e <code>"friends"</code> . Você pode definir essas propriedades de objeto para quaisquer valores desejados, desde que <code>"name"</code> seja uma cadeia, <code>"legs"</code> e <code>"tails"</code> sejam números e <code>"friends"</code> seja uma matriz. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>myDog</code> deve conter o <code>name</code> da propriedade e deve ser uma <code>string</code> .
|
||||
testString: 'assert((function(z){if(z.hasOwnProperty("name") && z.name !== undefined && typeof z.name === "string"){return true;}else{return false;}})(myDog), "<code>myDog</code> should contain the property <code>name</code> and it should be a <code>string</code>.");'
|
||||
- text: <code>myDog</code> deve conter as <code>legs</code> da propriedade e deve ser um <code>number</code> .
|
||||
testString: 'assert((function(z){if(z.hasOwnProperty("legs") && z.legs !== undefined && typeof z.legs === "number"){return true;}else{return false;}})(myDog), "<code>myDog</code> should contain the property <code>legs</code> and it should be a <code>number</code>.");'
|
||||
- text: <code>myDog</code> deve conter as <code>tails</code> da propriedade e deve ser um <code>number</code> .
|
||||
testString: 'assert((function(z){if(z.hasOwnProperty("tails") && z.tails !== undefined && typeof z.tails === "number"){return true;}else{return false;}})(myDog), "<code>myDog</code> should contain the property <code>tails</code> and it should be a <code>number</code>.");'
|
||||
- text: <code>myDog</code> deve conter os <code>friends</code> da propriedade e deve ser um <code>array</code> .
|
||||
testString: 'assert((function(z){if(z.hasOwnProperty("friends") && z.friends !== undefined && Array.isArray(z.friends)){return true;}else{return false;}})(myDog), "<code>myDog</code> should contain the property <code>friends</code> and it should be an <code>array</code>.");'
|
||||
- text: <code>myDog</code> deve conter apenas todas as propriedades dadas.
|
||||
testString: 'assert((function(z){return Object.keys(z).length === 4;})(myDog), "<code>myDog</code> should only contain all the given properties.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var ourDog = {
|
||||
"name": "Camper",
|
||||
"legs": 4,
|
||||
"tails": 1,
|
||||
"friends": ["everything!"]
|
||||
};
|
||||
|
||||
// Only change code below this line.
|
||||
|
||||
var myDog = {
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,82 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244dc
|
||||
title: Chaining If Else Statements
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Encadeamento Se Mais Declarações
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> <code>if/else</code> instruções podem ser encadeadas para lógica complexa. Aqui está o <dfn>pseudocódigo</dfn> de várias instruções encadeadas <code>if</code> / <code>else if</code> : <blockquote> if ( <em>condição1</em> ) { <br> <em>statement1</em> <br> } else if ( <em>condição2</em> ) { <br> <em>statement2</em> <br> } else if ( <em>condição3</em> ) { <br> <em>statement3</em> <br> . . . <br> } outro { <br> <em>statementN</em> <br> } </blockquote></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Escreva encadeado <code>if</code> / <code>else if</code> instruções preencherem as seguintes condições: <code>num < 5</code> - return "Tiny" <br> <code>num < 10</code> - retorna "Pequeno" <br> <code>num < 15</code> - return "Medium" <br> <code>num < 20</code> - retorna "Grande" <br> <code>num >= 20</code> - retornar "Enorme" </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Você deve ter pelo menos quatro <code>else</code> declarações
|
||||
testString: 'assert(code.match(/else/g).length > 3, "You should have at least four <code>else</code> statements");'
|
||||
- text: Você deve ter pelo menos quatro declarações <code>if</code>
|
||||
testString: 'assert(code.match(/if/g).length > 3, "You should have at least four <code>if</code> statements");'
|
||||
- text: Você deve ter pelo menos uma declaração de <code>return</code>
|
||||
testString: 'assert(code.match(/return/g).length >= 1, "You should have at least one <code>return</code> statement");'
|
||||
- text: <code>testSize(0)</code> deve retornar "minúsculo"
|
||||
testString: 'assert(testSize(0) === "Tiny", "<code>testSize(0)</code> should return "Tiny"");'
|
||||
- text: <code>testSize(4)</code> deve retornar "minúsculo"
|
||||
testString: 'assert(testSize(4) === "Tiny", "<code>testSize(4)</code> should return "Tiny"");'
|
||||
- text: <code>testSize(5)</code> deve retornar "Small"
|
||||
testString: 'assert(testSize(5) === "Small", "<code>testSize(5)</code> should return "Small"");'
|
||||
- text: <code>testSize(8)</code> deve retornar "Small"
|
||||
testString: 'assert(testSize(8) === "Small", "<code>testSize(8)</code> should return "Small"");'
|
||||
- text: <code>testSize(10)</code> deve retornar "Medium"
|
||||
testString: 'assert(testSize(10) === "Medium", "<code>testSize(10)</code> should return "Medium"");'
|
||||
- text: <code>testSize(14)</code> deve retornar "Medium"
|
||||
testString: 'assert(testSize(14) === "Medium", "<code>testSize(14)</code> should return "Medium"");'
|
||||
- text: <code>testSize(15)</code> deve retornar "Large"
|
||||
testString: 'assert(testSize(15) === "Large", "<code>testSize(15)</code> should return "Large"");'
|
||||
- text: <code>testSize(17)</code> deve retornar "Large"
|
||||
testString: 'assert(testSize(17) === "Large", "<code>testSize(17)</code> should return "Large"");'
|
||||
- text: <code>testSize(20)</code> deve retornar "Enorme"
|
||||
testString: 'assert(testSize(20) === "Huge", "<code>testSize(20)</code> should return "Huge"");'
|
||||
- text: <code>testSize(25)</code> deve retornar "Enorme"
|
||||
testString: 'assert(testSize(25) === "Huge", "<code>testSize(25)</code> should return "Huge"");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function testSize(num) {
|
||||
// Only change code below this line
|
||||
|
||||
|
||||
return "Change Me";
|
||||
// Only change code above this line
|
||||
}
|
||||
|
||||
// Change this value to test
|
||||
testSize(7);
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,51 +0,0 @@
|
||||
---
|
||||
id: bd7123c9c441eddfaeb4bdef
|
||||
title: Comment Your JavaScript Code
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Comente seu código JavaScript
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Comentários são linhas de código que o JavaScript irá ignorar intencionalmente. Os comentários são uma ótima maneira de deixar anotações para você e para outras pessoas que mais tarde precisarão descobrir o que esse código faz. Existem duas maneiras de escrever comentários em JavaScript: Usar o <code>//</code> dirá JavaScript para ignorar o restante do texto na linha atual: <blockquote> // Este é um comentário em linha. </blockquote> Você pode fazer um comentário de várias linhas começando com <code>/*</code> e terminando com <code>*/</code> : <blockquote> /* Isto é um <br> comentário de várias linhas * / </blockquote> <strong>Melhor pratica</strong> <br> Conforme você escreve o código, você deve adicionar regularmente comentários para esclarecer a função de partes do seu código. Bons comentários podem ajudar a comunicar a intenção do seu código - tanto para os outros <em>quanto</em> para o seu futuro. </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Tente criar um de cada tipo de comentário. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Crie um <code>//</code> comentário de estilo que contenha pelo menos cinco letras.
|
||||
testString: 'assert(code.match(/(\/\/)...../g), "Create a <code>//</code> style comment that contains at least five letters.");'
|
||||
- text: Crie um comentário <code>/* */</code> style que contenha pelo menos cinco letras.
|
||||
testString: 'assert(code.match(/(\/\*)([^\/]{5,})(?=\*\/)/gm), "Create a <code>/* */</code> style comment that contains at least five letters.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// Comentário
|
||||
/* Aqui também pode ser inserido um comentário */
|
||||
```
|
||||
</section>
|
@ -1,64 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244d0
|
||||
title: Comparison with the Equality Operator
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Comparação com o operador de igualdade
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Existem muitos <dfn>operadores de comparação</dfn> em JavaScript. Todos esses operadores retornam um valor booleano <code>true</code> ou <code>false</code> . O operador mais básico é o operador de igualdade <code>==</code> . O operador de igualdade compara dois valores e retorna <code>true</code> se eles forem equivalentes ou <code>false</code> se não forem. Observe que a igualdade é diferente da atribuição ( <code>=</code> ), que atribui o valor à direita do operador a uma variável à esquerda. <blockquote> function equalityTest (myVal) { <br> if (myVal == 10) { <br> return "Equal"; <br> } <br> return "Não igual"; <br> } </blockquote> Se <code>myVal</code> for igual a <code>10</code> , o operador de igualdade retornará <code>true</code> , portanto o código nas chaves será executado e a função retornará <code>"Equal"</code> . Caso contrário, a função retornará <code>"Not Equal"</code> . Para que o JavaScript compare dois <code>data types</code> diferentes (por exemplo, <code>numbers</code> e <code>strings</code> ), ele deve converter um tipo em outro. Isso é conhecido como "Type Coerção". Uma vez feito, no entanto, ele pode comparar os termos da seguinte forma: <blockquote> 1 == 1 // verdadeiro <br> 1 == 2 // false <br> 1 == '1' // verdadeiro <br> "3" == 3 // verdadeiro </blockquote></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Adicione o <code>equality operator</code> à linha indicada para que a função retorne "Equal" quando <code>val</code> é equivalente a <code>12</code> </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>testEqual(10)</code> deve retornar "não igual"
|
||||
testString: 'assert(testEqual(10) === "Not Equal", "<code>testEqual(10)</code> should return "Not Equal"");'
|
||||
- text: <code>testEqual(12)</code> deve retornar "Equal"
|
||||
testString: 'assert(testEqual(12) === "Equal", "<code>testEqual(12)</code> should return "Equal"");'
|
||||
- text: <code>testEqual("12")</code> deve retornar "Igual"
|
||||
testString: 'assert(testEqual("12") === "Equal", "<code>testEqual("12")</code> should return "Equal"");'
|
||||
- text: Você deve usar o operador <code>==</code>
|
||||
testString: 'assert(code.match(/==/g) && !code.match(/===/g), "You should use the <code>==</code> operator");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Setup
|
||||
function testEqual(val) {
|
||||
if (val) { // Change this line
|
||||
return "Equal";
|
||||
}
|
||||
return "Not Equal";
|
||||
}
|
||||
|
||||
// Change this value to test
|
||||
testEqual(10);
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,76 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244d4
|
||||
title: Comparison with the Greater Than Operator
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Comparação com o operador Maior que
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> O operador maior que ( <code>></code> ) compara os valores de dois números. Se o número à esquerda for maior que o número à direita, ele retornará <code>true</code> . Caso contrário, retorna <code>false</code> . Como o operador de igualdade, maior que o operador converterá tipos de dados de valores durante a comparação. <strong>Exemplos</strong> <blockquote> 5> 3 // verdadeiro <br> 7> '3' // verdadeiro <br> 2> 3 // falso <br> '1'> 9 // falso </blockquote></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Adicione o operador <code>greater than</code> às linhas indicadas para que as instruções de retorno façam sentido. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>testGreaterThan(0)</code> deve retornar "10 ou menos"
|
||||
testString: 'assert(testGreaterThan(0) === "10 or Under", "<code>testGreaterThan(0)</code> should return "10 or Under"");'
|
||||
- text: <code>testGreaterThan(10)</code> deve retornar "10 ou menos"
|
||||
testString: 'assert(testGreaterThan(10) === "10 or Under", "<code>testGreaterThan(10)</code> should return "10 or Under"");'
|
||||
- text: <code>testGreaterThan(11)</code> deve retornar "Mais de 10"
|
||||
testString: 'assert(testGreaterThan(11) === "Over 10", "<code>testGreaterThan(11)</code> should return "Over 10"");'
|
||||
- text: <code>testGreaterThan(99)</code> deve retornar "Mais de 10"
|
||||
testString: 'assert(testGreaterThan(99) === "Over 10", "<code>testGreaterThan(99)</code> should return "Over 10"");'
|
||||
- text: <code>testGreaterThan(100)</code> deve retornar "Mais de 10"
|
||||
testString: 'assert(testGreaterThan(100) === "Over 10", "<code>testGreaterThan(100)</code> should return "Over 10"");'
|
||||
- text: <code>testGreaterThan(101)</code> deve retornar "Mais de 100"
|
||||
testString: 'assert(testGreaterThan(101) === "Over 100", "<code>testGreaterThan(101)</code> should return "Over 100"");'
|
||||
- text: <code>testGreaterThan(150)</code> deve retornar "Mais de 100"
|
||||
testString: 'assert(testGreaterThan(150) === "Over 100", "<code>testGreaterThan(150)</code> should return "Over 100"");'
|
||||
- text: Você deve usar o operador <code>></code> pelo menos duas vezes
|
||||
testString: 'assert(code.match(/val\s*>\s*("|")*\d+("|")*/g).length > 1, "You should use the <code>></code> operator at least twice");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function testGreaterThan(val) {
|
||||
if (val) { // Change this line
|
||||
return "Over 100";
|
||||
}
|
||||
|
||||
if (val) { // Change this line
|
||||
return "Over 10";
|
||||
}
|
||||
|
||||
return "10 or Under";
|
||||
}
|
||||
|
||||
// Change this value to test
|
||||
testGreaterThan(10);
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,76 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244d5
|
||||
title: Comparison with the Greater Than Or Equal To Operator
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Comparação com o maior que ou igual ao operador
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> O <code>greater than or equal to</code> operador ( <code>>=</code> ) compara os valores de dois números. Se o número à esquerda for maior ou igual ao número à direita, ele retornará <code>true</code> . Caso contrário, retorna <code>false</code> . Como o operador de igualdade, <code>greater than or equal to</code> operador converterá os tipos de dados durante a comparação. <strong>Exemplos</strong> <blockquote> 6> = 6 // verdadeiro <br> 7> = '3' // verdadeiro <br> 2> = 3 // falso <br> '7'> = 9 // falso </blockquote></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Adicione o operador <code>greater than or equal to</code> às linhas indicadas para que as instruções de retorno façam sentido. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>testGreaterOrEqual(0)</code> deve retornar "Menor que 10"
|
||||
testString: 'assert(testGreaterOrEqual(0) === "Less than 10", "<code>testGreaterOrEqual(0)</code> should return "Less than 10"");'
|
||||
- text: <code>testGreaterOrEqual(9)</code> deve retornar "Menor que 10"
|
||||
testString: 'assert(testGreaterOrEqual(9) === "Less than 10", "<code>testGreaterOrEqual(9)</code> should return "Less than 10"");'
|
||||
- text: <code>testGreaterOrEqual(10)</code> deve retornar "10 ou mais"
|
||||
testString: 'assert(testGreaterOrEqual(10) === "10 or Over", "<code>testGreaterOrEqual(10)</code> should return "10 or Over"");'
|
||||
- text: <code>testGreaterOrEqual(11)</code> deve retornar "10 ou mais"
|
||||
testString: 'assert(testGreaterOrEqual(11) === "10 or Over", "<code>testGreaterOrEqual(11)</code> should return "10 or Over"");'
|
||||
- text: <code>testGreaterOrEqual(19)</code> deve retornar "10 ou mais"
|
||||
testString: 'assert(testGreaterOrEqual(19) === "10 or Over", "<code>testGreaterOrEqual(19)</code> should return "10 or Over"");'
|
||||
- text: <code>testGreaterOrEqual(100)</code> deve retornar "20 ou mais"
|
||||
testString: 'assert(testGreaterOrEqual(100) === "20 or Over", "<code>testGreaterOrEqual(100)</code> should return "20 or Over"");'
|
||||
- text: <code>testGreaterOrEqual(21)</code> deve retornar "20 ou mais"
|
||||
testString: 'assert(testGreaterOrEqual(21) === "20 or Over", "<code>testGreaterOrEqual(21)</code> should return "20 or Over"");'
|
||||
- text: Você deve usar o operador <code>>=</code> pelo menos duas vezes
|
||||
testString: 'assert(code.match(/val\s*>=\s*("|")*\d+("|")*/g).length > 1, "You should use the <code>>=</code> operator at least twice");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function testGreaterOrEqual(val) {
|
||||
if (val) { // Change this line
|
||||
return "20 or Over";
|
||||
}
|
||||
|
||||
if (val) { // Change this line
|
||||
return "10 or Over";
|
||||
}
|
||||
|
||||
return "Less than 10";
|
||||
}
|
||||
|
||||
// Change this value to test
|
||||
testGreaterOrEqual(10);
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,68 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244d2
|
||||
title: Comparison with the Inequality Operator
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Comparação com o operador Inequality
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> O operador de desigualdade ( <code>!=</code> ) É o oposto do operador de igualdade. Significa "Não igual" e retorna <code>false</code> onde a igualdade retornaria <code>true</code> e <em>vice-versa</em> . Como o operador de igualdade, o operador de desigualdade converterá tipos de dados de valores durante a comparação. <strong>Exemplos</strong> <blockquote> 1! = 2 // verdadeiro <br> 1! = "1" // false <br> 1! = '1' // false <br> 1! = Verdadeiro // falso <br> 0! = Falso // falso </blockquote></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Adicione o operador de desigualdade <code>!=</code> Na instrução <code>if</code> para que a função retorne "Not Equal" quando <code>val</code> não for equivalente a <code>99</code> </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>testNotEqual(99)</code> deve retornar "igual"
|
||||
testString: 'assert(testNotEqual(99) === "Equal", "<code>testNotEqual(99)</code> should return "Equal"");'
|
||||
- text: <code>testNotEqual("99")</code> deve retornar "igual"
|
||||
testString: 'assert(testNotEqual("99") === "Equal", "<code>testNotEqual("99")</code> should return "Equal"");'
|
||||
- text: <code>testNotEqual(12)</code> deve retornar "não igual"
|
||||
testString: 'assert(testNotEqual(12) === "Not Equal", "<code>testNotEqual(12)</code> should return "Not Equal"");'
|
||||
- text: <code>testNotEqual("12")</code> deve retornar "não igual"
|
||||
testString: 'assert(testNotEqual("12") === "Not Equal", "<code>testNotEqual("12")</code> should return "Not Equal"");'
|
||||
- text: <code>testNotEqual("bob")</code> deve retornar "não igual"
|
||||
testString: 'assert(testNotEqual("bob") === "Not Equal", "<code>testNotEqual("bob")</code> should return "Not Equal"");'
|
||||
- text: Você deve usar o operador <code>!=</code>
|
||||
testString: 'assert(code.match(/(?!!==)!=/), "You should use the <code>!=</code> operator");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Setup
|
||||
function testNotEqual(val) {
|
||||
if (val) { // Change this line
|
||||
return "Not Equal";
|
||||
}
|
||||
return "Equal";
|
||||
}
|
||||
|
||||
// Change this value to test
|
||||
testNotEqual(10);
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,74 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244d6
|
||||
title: Comparison with the Less Than Operator
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Comparação com o menor que o operador
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> O operador <dfn>menor que</dfn> ( <code><</code> ) compara os valores de dois números. Se o número à esquerda for menor que o número à direita, ele retornará <code>true</code> . Caso contrário, retorna <code>false</code> . Como o operador de igualdade, o operador <dfn>menor que</dfn> converte tipos de dados durante a comparação. <strong>Exemplos</strong> <blockquote> 2 <5 // verdadeiro <br> '3' <7 // verdadeiro <br> 5 <5 // falso <br> 3 <2 // falso <br> '8' <4 // falso </blockquote></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Adicione o operador <code>less than</code> às linhas indicadas para que as instruções de retorno façam sentido. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>testLessThan(0)</code> deve retornar "Abaixo de 25"
|
||||
testString: 'assert(testLessThan(0) === "Under 25", "<code>testLessThan(0)</code> should return "Under 25"");'
|
||||
- text: <code>testLessThan(24)</code> deve retornar "Abaixo de 25"
|
||||
testString: 'assert(testLessThan(24) === "Under 25", "<code>testLessThan(24)</code> should return "Under 25"");'
|
||||
- text: <code>testLessThan(25)</code> deve retornar "Under 55"
|
||||
testString: 'assert(testLessThan(25) === "Under 55", "<code>testLessThan(25)</code> should return "Under 55"");'
|
||||
- text: <code>testLessThan(54)</code> deve retornar "Under 55"
|
||||
testString: 'assert(testLessThan(54) === "Under 55", "<code>testLessThan(54)</code> should return "Under 55"");'
|
||||
- text: <code>testLessThan(55)</code> deve retornar "55 ou mais"
|
||||
testString: 'assert(testLessThan(55) === "55 or Over", "<code>testLessThan(55)</code> should return "55 or Over"");'
|
||||
- text: <code>testLessThan(99)</code> deve retornar "55 ou mais"
|
||||
testString: 'assert(testLessThan(99) === "55 or Over", "<code>testLessThan(99)</code> should return "55 or Over"");'
|
||||
- text: Você deve usar o operador <code><</code> pelo menos duas vezes
|
||||
testString: 'assert(code.match(/val\s*<\s*("|")*\d+("|")*/g).length > 1, "You should use the <code><</code> operator at least twice");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function testLessThan(val) {
|
||||
if (val) { // Change this line
|
||||
return "Under 25";
|
||||
}
|
||||
|
||||
if (val) { // Change this line
|
||||
return "Under 55";
|
||||
}
|
||||
|
||||
return "55 or Over";
|
||||
}
|
||||
|
||||
// Change this value to test
|
||||
testLessThan(10);
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,76 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244d7
|
||||
title: Comparison with the Less Than Or Equal To Operator
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Comparação com o menor ou igual ao operador
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> O operador <code>less than or equal to</code> ( <code><=</code> ) compara os valores de dois números. Se o número à esquerda for menor ou igual ao número à direita, ele retornará <code>true</code> . Se o número à esquerda for maior que o número à direita, ele retornará <code>false</code> . Como o operador de igualdade, <code>less than or equal to</code> converte tipos de dados. <strong>Exemplos</strong> <blockquote> 4 <= 5 // verdadeiro <br> '7' <= 7 // verdadeiro <br> 5 <= 5 // verdadeiro <br> 3 <= 2 // falso <br> '8' <= 4 // falso </blockquote></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Adicione o operador <code>less than or equal to</code> das linhas indicadas para que as instruções de retorno façam sentido. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>testLessOrEqual(0)</code> deve retornar "Menor ou igual a 12"
|
||||
testString: 'assert(testLessOrEqual(0) === "Smaller Than or Equal to 12", "<code>testLessOrEqual(0)</code> should return "Smaller Than or Equal to 12"");'
|
||||
- text: <code>testLessOrEqual(11)</code> deve retornar "Menor ou igual a 12"
|
||||
testString: 'assert(testLessOrEqual(11) === "Smaller Than or Equal to 12", "<code>testLessOrEqual(11)</code> should return "Smaller Than or Equal to 12"");'
|
||||
- text: <code>testLessOrEqual(12)</code> deve retornar "Menor ou igual a 12"
|
||||
testString: 'assert(testLessOrEqual(12) === "Smaller Than or Equal to 12", "<code>testLessOrEqual(12)</code> should return "Smaller Than or Equal to 12"");'
|
||||
- text: <code>testLessOrEqual(23)</code> deve retornar "Menor ou igual a 24"
|
||||
testString: 'assert(testLessOrEqual(23) === "Smaller Than or Equal to 24", "<code>testLessOrEqual(23)</code> should return "Smaller Than or Equal to 24"");'
|
||||
- text: <code>testLessOrEqual(24)</code> deve retornar "Menor ou igual a 24"
|
||||
testString: 'assert(testLessOrEqual(24) === "Smaller Than or Equal to 24", "<code>testLessOrEqual(24)</code> should return "Smaller Than or Equal to 24"");'
|
||||
- text: <code>testLessOrEqual(25)</code> deve retornar "mais de 24"
|
||||
testString: 'assert(testLessOrEqual(25) === "More Than 24", "<code>testLessOrEqual(25)</code> should return "More Than 24"");'
|
||||
- text: <code>testLessOrEqual(55)</code> deve retornar "mais de 24"
|
||||
testString: 'assert(testLessOrEqual(55) === "More Than 24", "<code>testLessOrEqual(55)</code> should return "More Than 24"");'
|
||||
- text: Você deve usar o operador <code><=</code> pelo menos duas vezes
|
||||
testString: 'assert(code.match(/val\s*<=\s*("|")*\d+("|")*/g).length > 1, "You should use the <code><=</code> operator at least twice");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function testLessOrEqual(val) {
|
||||
if (val) { // Change this line
|
||||
return "Smaller Than or Equal to 12";
|
||||
}
|
||||
|
||||
if (val) { // Change this line
|
||||
return "Smaller Than or Equal to 24";
|
||||
}
|
||||
|
||||
return "More Than 24";
|
||||
}
|
||||
|
||||
// Change this value to test
|
||||
testLessOrEqual(10);
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,64 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244d1
|
||||
title: Comparison with the Strict Equality Operator
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Comparação com o operador Strict Equality
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> A igualdade estrita ( <code>===</code> ) é a contrapartida do operador de igualdade ( <code>==</code> ). No entanto, ao contrário do operador de igualdade, que tenta converter os dois valores sendo comparados a um tipo comum, o operador de igualdade estrita não executa uma conversão de tipo. Se os valores que estão sendo comparados tiverem tipos diferentes, eles serão considerados desiguais e o operador de igualdade estrita retornará false. <strong>Exemplos</strong> <blockquote> 3 === 3 // verdadeiro <br> 3 === '3' // false </blockquote> No segundo exemplo, <code>3</code> é um tipo <code>Number</code> e <code>'3'</code> é um tipo <code>String</code> . </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Use o operador de igualdade estrito na instrução <code>if</code> para que a função retorne "Equal" quando <code>val</code> for estritamente igual a <code>7</code> </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>testStrict(10)</code> deve retornar "não igual"
|
||||
testString: 'assert(testStrict(10) === "Not Equal", "<code>testStrict(10)</code> should return "Not Equal"");'
|
||||
- text: <code>testStrict(7)</code> deve retornar "igual"
|
||||
testString: 'assert(testStrict(7) === "Equal", "<code>testStrict(7)</code> should return "Equal"");'
|
||||
- text: <code>testStrict("7")</code> deve retornar "não igual"
|
||||
testString: 'assert(testStrict("7") === "Not Equal", "<code>testStrict("7")</code> should return "Not Equal"");'
|
||||
- text: Você deve usar o operador <code>===</code>
|
||||
testString: 'assert(code.match(/(val\s*===\s*\d+)|(\d+\s*===\s*val)/g).length > 0, "You should use the <code>===</code> operator");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Setup
|
||||
function testStrict(val) {
|
||||
if (val) { // Change this line
|
||||
return "Equal";
|
||||
}
|
||||
return "Not Equal";
|
||||
}
|
||||
|
||||
// Change this value to test
|
||||
testStrict(10);
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,71 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244d3
|
||||
title: Comparison with the Strict Inequality Operator
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Comparação com o Operador Estrito da Desigualdade
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> O operador de desigualdade restrita ( <code>!==</code> ) é o oposto lógico do operador de igualdade estrito. Significa "estritamente não igual" e retorna <code>false</code> onde a igualdade estrita retornaria <code>true</code> e <em>vice-versa</em> . A desigualdade estrita não converte tipos de dados. <strong>Exemplos</strong> <blockquote> 3! == 3 // false <br> 3! == '3' // true <br> 4! == 3 // verdadeiro </blockquote></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Adicione o <code>strict inequality operator</code> à instrução <code>if</code> para que a função retorne "Not Equal" quando <code>val</code> não for estritamente igual a <code>17</code> </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>testStrictNotEqual(17)</code> deve retornar "Igual"
|
||||
testString: 'assert(testStrictNotEqual(17) === "Equal", "<code>testStrictNotEqual(17)</code> should return "Equal"");'
|
||||
- text: <code>testStrictNotEqual("17")</code> deve retornar "não igual"
|
||||
testString: 'assert(testStrictNotEqual("17") === "Not Equal", "<code>testStrictNotEqual("17")</code> should return "Not Equal"");'
|
||||
- text: <code>testStrictNotEqual(12)</code> deve retornar "não igual"
|
||||
testString: 'assert(testStrictNotEqual(12) === "Not Equal", "<code>testStrictNotEqual(12)</code> should return "Not Equal"");'
|
||||
- text: <code>testStrictNotEqual("bob")</code> deve retornar "não igual"
|
||||
testString: 'assert(testStrictNotEqual("bob") === "Not Equal", "<code>testStrictNotEqual("bob")</code> should return "Not Equal"");'
|
||||
- text: Você deve usar o operador <code>!==</code>
|
||||
testString: 'assert(code.match(/(val\s*!==\s*\d+)|(\d+\s*!==\s*val)/g).length > 0, "You should use the <code>!==</code> operator");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Setup
|
||||
function testStrictNotEqual(val) {
|
||||
// Only Change Code Below this Line
|
||||
|
||||
if (val) {
|
||||
|
||||
// Only Change Code Above this Line
|
||||
|
||||
return "Not Equal";
|
||||
}
|
||||
return "Equal";
|
||||
}
|
||||
|
||||
// Change this value to test
|
||||
testStrictNotEqual(10);
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,81 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244d8
|
||||
title: Comparisons with the Logical And Operator
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Comparações com o Logical And Operator
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Às vezes você precisará testar mais de uma coisa de cada vez. O <dfn>lógico e o</dfn> operador ( <code>&&</code> ) retornam <code>true</code> se e somente se os <dfn>operandos</dfn> à esquerda e à direita dele forem verdadeiros. O mesmo efeito pode ser obtido aninhando uma instrução if dentro de outra se: <blockquote> if (num> 5) { <br> if (num <10) { <br> return "Sim"; <br> } <br> } <br> return "não"; </blockquote> só retornará "Sim" se <code>num</code> for maior que <code>5</code> e menor que <code>10</code> . A mesma lógica pode ser escrita como: <blockquote> if (num> 5 && num <10) { <br> return "Sim"; <br> } <br> return "não"; </blockquote></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Combine as duas instruções if em uma instrução que retornará <code>"Yes"</code> se <code>val</code> for menor ou igual a <code>50</code> e maior ou igual a <code>25</code> . Caso contrário, retornará <code>"No"</code> . </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Você deve usar o operador <code>&&</code> uma vez
|
||||
testString: 'assert(code.match(/&&/g).length === 1, "You should use the <code>&&</code> operator once");'
|
||||
- text: Você deve ter apenas uma declaração <code>if</code>
|
||||
testString: 'assert(code.match(/if/g).length === 1, "You should only have one <code>if</code> statement");'
|
||||
- text: <code>testLogicalAnd(0)</code> deve retornar "Não"
|
||||
testString: 'assert(testLogicalAnd(0) === "No", "<code>testLogicalAnd(0)</code> should return "No"");'
|
||||
- text: <code>testLogicalAnd(24)</code> deve retornar "Não"
|
||||
testString: 'assert(testLogicalAnd(24) === "No", "<code>testLogicalAnd(24)</code> should return "No"");'
|
||||
- text: <code>testLogicalAnd(25)</code> deve retornar "Sim"
|
||||
testString: 'assert(testLogicalAnd(25) === "Yes", "<code>testLogicalAnd(25)</code> should return "Yes"");'
|
||||
- text: <code>testLogicalAnd(30)</code> deve retornar "Sim"
|
||||
testString: 'assert(testLogicalAnd(30) === "Yes", "<code>testLogicalAnd(30)</code> should return "Yes"");'
|
||||
- text: <code>testLogicalAnd(50)</code> deve retornar "Sim"
|
||||
testString: 'assert(testLogicalAnd(50) === "Yes", "<code>testLogicalAnd(50)</code> should return "Yes"");'
|
||||
- text: <code>testLogicalAnd(51)</code> deve retornar "Não"
|
||||
testString: 'assert(testLogicalAnd(51) === "No", "<code>testLogicalAnd(51)</code> should return "No"");'
|
||||
- text: <code>testLogicalAnd(75)</code> deve retornar "Não"
|
||||
testString: 'assert(testLogicalAnd(75) === "No", "<code>testLogicalAnd(75)</code> should return "No"");'
|
||||
- text: <code>testLogicalAnd(80)</code> deve retornar "Não"
|
||||
testString: 'assert(testLogicalAnd(80) === "No", "<code>testLogicalAnd(80)</code> should return "No"");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function testLogicalAnd(val) {
|
||||
// Only change code below this line
|
||||
|
||||
if (val) {
|
||||
if (val) {
|
||||
return "Yes";
|
||||
}
|
||||
}
|
||||
|
||||
// Only change code above this line
|
||||
return "No";
|
||||
}
|
||||
|
||||
// Change this value to test
|
||||
testLogicalAnd(10);
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,83 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244d9
|
||||
title: Comparisons with the Logical Or Operator
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Comparações com o lógico ou operador
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> O <dfn>lógico ou</dfn> operador ( <code>||</code> ) retorna <code>true</code> se qualquer um dos <dfn>operandos</dfn> for <code>true</code> . Caso contrário, retorna <code>false</code> . O <dfn>lógico ou</dfn> operador é composto de dois símbolos de pipe ( <code>|</code> ). Isso geralmente pode ser encontrado entre as teclas Backspace e Enter. O padrão abaixo deve parecer familiar a partir de waypoints anteriores: <blockquote> if (num> 10) { <br> return "não"; <br> } <br> if (num <5) { <br> return "não"; <br> } <br> return "Sim"; </blockquote> retornará "Sim" somente se <code>num</code> for entre <code>5</code> e <code>10</code> (5 e 10 incluídos). A mesma lógica pode ser escrita como: <blockquote> if (num> 10 || num <5) { <br> return "não"; <br> } <br> return "Sim"; </blockquote></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Combine as duas declarações <code>if</code> em uma declaração que retorne <code>"Outside"</code> se <code>val</code> não estiver entre <code>10</code> e <code>20</code> , inclusive. Caso contrário, retorne <code>"Inside"</code> . </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Você deve usar o <code>||</code> operador uma vez
|
||||
testString: 'assert(code.match(/\|\|/g).length === 1, "You should use the <code>||</code> operator once");'
|
||||
- text: Você deve ter apenas uma declaração <code>if</code>
|
||||
testString: 'assert(code.match(/if/g).length === 1, "You should only have one <code>if</code> statement");'
|
||||
- text: <code>testLogicalOr(0)</code> deve retornar "Outside"
|
||||
testString: 'assert(testLogicalOr(0) === "Outside", "<code>testLogicalOr(0)</code> should return "Outside"");'
|
||||
- text: <code>testLogicalOr(9)</code> deve retornar "Outside"
|
||||
testString: 'assert(testLogicalOr(9) === "Outside", "<code>testLogicalOr(9)</code> should return "Outside"");'
|
||||
- text: <code>testLogicalOr(10)</code> deve retornar "Inside"
|
||||
testString: 'assert(testLogicalOr(10) === "Inside", "<code>testLogicalOr(10)</code> should return "Inside"");'
|
||||
- text: <code>testLogicalOr(15)</code> deve retornar "Inside"
|
||||
testString: 'assert(testLogicalOr(15) === "Inside", "<code>testLogicalOr(15)</code> should return "Inside"");'
|
||||
- text: <code>testLogicalOr(19)</code> deve retornar "Inside"
|
||||
testString: 'assert(testLogicalOr(19) === "Inside", "<code>testLogicalOr(19)</code> should return "Inside"");'
|
||||
- text: <code>testLogicalOr(20)</code> deve retornar "Inside"
|
||||
testString: 'assert(testLogicalOr(20) === "Inside", "<code>testLogicalOr(20)</code> should return "Inside"");'
|
||||
- text: <code>testLogicalOr(21)</code> deve retornar "Outside"
|
||||
testString: 'assert(testLogicalOr(21) === "Outside", "<code>testLogicalOr(21)</code> should return "Outside"");'
|
||||
- text: <code>testLogicalOr(25)</code> deve retornar "Outside"
|
||||
testString: 'assert(testLogicalOr(25) === "Outside", "<code>testLogicalOr(25)</code> should return "Outside"");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function testLogicalOr(val) {
|
||||
// Only change code below this line
|
||||
|
||||
if (val) {
|
||||
return "Outside";
|
||||
}
|
||||
|
||||
if (val) {
|
||||
return "Outside";
|
||||
}
|
||||
|
||||
// Only change code above this line
|
||||
return "Inside";
|
||||
}
|
||||
|
||||
// Change this value to test
|
||||
testLogicalOr(15);
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,73 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244af
|
||||
title: Compound Assignment With Augmented Addition
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Atribuição composta com adição aumentada
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Na programação, é comum usar atribuições para modificar o conteúdo de uma variável. Lembre-se de que tudo à direita do sinal de igual é avaliado primeiro, então podemos dizer: <code>myVar = myVar + 5;</code> para adicionar <code>5</code> a <code>myVar</code> . Como esse é um padrão tão comum, há operadores que fazem uma operação matemática e uma atribuição em uma etapa. Um desses operadores é o operador <code>+=</code> . <blockquote> var myVar = 1; <br> myVar + = 5; <br> console.log (myVar); // Retorna 6 </blockquote></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Converta as atribuições de <code>a</code> , <code>b</code> e <code>c</code> para usar o operador <code>+=</code> . </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>a</code> deve ser igual a <code>15</code>
|
||||
testString: 'assert(a === 15, "<code>a</code> should equal <code>15</code>");'
|
||||
- text: <code>b</code> deve ser igual a <code>26</code>
|
||||
testString: 'assert(b === 26, "<code>b</code> should equal <code>26</code>");'
|
||||
- text: <code>c</code> deve ser igual a <code>19</code>
|
||||
testString: 'assert(c === 19, "<code>c</code> should equal <code>19</code>");'
|
||||
- text: Você deve usar o operador <code>+=</code> para cada variável
|
||||
testString: 'assert(code.match(/\+=/g).length === 3, "You should use the <code>+=</code> operator for each variable");'
|
||||
- text: Não modifique o código acima da linha
|
||||
testString: 'assert(/var a = 3;/.test(code) && /var b = 17;/.test(code) && /var c = 12;/.test(code), "Do not modify the code above the line");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
var a = 3;
|
||||
var b = 17;
|
||||
var c = 12;
|
||||
|
||||
// Only modify code below this line
|
||||
|
||||
a = a + 12;
|
||||
b = 9 + b;
|
||||
c = c + 7;
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,73 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244b2
|
||||
title: Compound Assignment With Augmented Division
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Atribuição Composta Com Divisão Aumentada
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> O operador <code>/=</code> divide uma variável por outro número. <code>myVar = myVar / 5;</code> Vai dividir <code>myVar</code> por <code>5</code> . Isso pode ser reescrito como: <code>myVar /= 5;</code> </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Converta as atribuições de <code>a</code> , <code>b</code> e <code>c</code> para usar o operador <code>/=</code> . </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>a</code> deve ser igual a <code>4</code>
|
||||
testString: 'assert(a === 4, "<code>a</code> should equal <code>4</code>");'
|
||||
- text: <code>b</code> deve ser igual a <code>27</code>
|
||||
testString: 'assert(b === 27, "<code>b</code> should equal <code>27</code>");'
|
||||
- text: <code>c</code> deve ser igual a <code>3</code>
|
||||
testString: 'assert(c === 3, "<code>c</code> should equal <code>3</code>");'
|
||||
- text: Você deve usar o operador <code>/=</code> para cada variável
|
||||
testString: 'assert(code.match(/\/=/g).length === 3, "You should use the <code>/=</code> operator for each variable");'
|
||||
- text: Não modifique o código acima da linha
|
||||
testString: 'assert(/var a = 48;/.test(code) && /var b = 108;/.test(code) && /var c = 33;/.test(code), "Do not modify the code above the line");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
var a = 48;
|
||||
var b = 108;
|
||||
var c = 33;
|
||||
|
||||
// Only modify code below this line
|
||||
|
||||
a = a / 12;
|
||||
b = b / 4;
|
||||
c = c / 11;
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,73 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244b1
|
||||
title: Compound Assignment With Augmented Multiplication
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Atribuição Composta Com Multiplicação Aumentada
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> O operador <code>*=</code> multiplica uma variável por um número. <code>myVar = myVar * 5;</code> irá multiplicar <code>myVar</code> por <code>5</code> . Isso pode ser reescrito como: <code>myVar *= 5;</code> </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Converta as atribuições de <code>a</code> , <code>b</code> e <code>c</code> para usar o operador <code>*=</code> . </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>a</code> deve ser igual a <code>25</code>
|
||||
testString: 'assert(a === 25, "<code>a</code> should equal <code>25</code>");'
|
||||
- text: <code>b</code> deve ser igual a <code>36</code>
|
||||
testString: 'assert(b === 36, "<code>b</code> should equal <code>36</code>");'
|
||||
- text: <code>c</code> deve ser igual a <code>46</code>
|
||||
testString: 'assert(c === 46, "<code>c</code> should equal <code>46</code>");'
|
||||
- text: Você deve usar o operador <code>*=</code> para cada variável
|
||||
testString: 'assert(code.match(/\*=/g).length === 3, "You should use the <code>*=</code> operator for each variable");'
|
||||
- text: Não modifique o código acima da linha
|
||||
testString: 'assert(/var a = 5;/.test(code) && /var b = 12;/.test(code) && /var c = 4\.6;/.test(code), "Do not modify the code above the line");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
var a = 5;
|
||||
var b = 12;
|
||||
var c = 4.6;
|
||||
|
||||
// Only modify code below this line
|
||||
|
||||
a = a * 5;
|
||||
b = 3 * b;
|
||||
c = c * 10;
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,73 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244b0
|
||||
title: Compound Assignment With Augmented Subtraction
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Atribuição Composta com Subtração Aumentada
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Como o operador <code>+=</code> , <code>-=</code> subtrai um número de uma variável. <code>myVar = myVar - 5;</code> subtrairá <code>5</code> do <code>myVar</code> . Isso pode ser reescrito como: <code>myVar -= 5;</code> </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Converta as atribuições de <code>a</code> , <code>b</code> e <code>c</code> para usar o operador <code>-=</code> . </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>a</code> deve igual a <code>5</code>
|
||||
testString: 'assert(a === 5, "<code>a</code> should equal <code>5</code>");'
|
||||
- text: <code>b</code> deve ser igual a <code>-6</code>
|
||||
testString: 'assert(b === -6, "<code>b</code> should equal <code>-6</code>");'
|
||||
- text: <code>c</code> deve ser igual a <code>2</code>
|
||||
testString: 'assert(c === 2, "<code>c</code> should equal <code>2</code>");'
|
||||
- text: Você deve usar o operador <code>-=</code> para cada variável
|
||||
testString: 'assert(code.match(/-=/g).length === 3, "You should use the <code>-=</code> operator for each variable");'
|
||||
- text: Não modifique o código acima da linha
|
||||
testString: 'assert(/var a = 11;/.test(code) && /var b = 9;/.test(code) && /var c = 3;/.test(code), "Do not modify the code above the line");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
var a = 11;
|
||||
var b = 9;
|
||||
var c = 3;
|
||||
|
||||
// Only modify code below this line
|
||||
|
||||
a = a - 6;
|
||||
b = b - 15;
|
||||
c = c - 1;
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,68 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244b7
|
||||
title: Concatenating Strings with Plus Operator
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Concatenando Strings com Operador Plus
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Em JavaScript, quando o operador <code>+</code> é usado com um valor <code>String</code> , ele é chamado de operador de <dfn>concatenação</dfn> . Você pode construir uma nova string a partir de outras strings, <dfn>concatenando</dfn> -as juntas. <strong>Exemplo</strong> <blockquote> 'Meu nome é Alan,' concordo '. </blockquote> <strong>Nota</strong> <br> Cuidado com os espaços. A concatenação não adiciona espaços entre as sequências concatenadas, portanto, você precisará adicioná-las você mesmo. </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Construa <code>myStr</code> partir das strings <code>"This is the start. "</code> E <code>"This is the end."</code> usando o operador <code>+</code> . </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>myStr</code> deve ter um valor de <code>This is the start. This is the end.</code>
|
||||
testString: 'assert(myStr === "This is the start. This is the end.", "<code>myStr</code> should have a value of <code>This is the start. This is the end.</code>");'
|
||||
- text: Use o operador <code>+</code> para construir <code>myStr</code>
|
||||
testString: 'assert(code.match(/([""]).*([""])\s*\+\s*([""]).*([""])/g).length > 1, "Use the <code>+</code> operator to build <code>myStr</code>");'
|
||||
- text: <code>myStr</code> deve ser criado usando a palavra-chave <code>var</code> .
|
||||
testString: 'assert(/var\s+myStr/.test(code), "<code>myStr</code> should be created using the <code>var</code> keyword.");'
|
||||
- text: Certifique-se de atribuir o resultado à variável <code>myStr</code> .
|
||||
testString: 'assert(/myStr\s*=/.test(code), "Make sure to assign the result to the <code>myStr</code> variable.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var ourStr = "I come first. " + "I come second.";
|
||||
|
||||
// Only change code below this line
|
||||
|
||||
var myStr;
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,65 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244b8
|
||||
title: Concatenating Strings with the Plus Equals Operator
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Concatenando Strings com o Operador Plus Equals
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Também podemos usar o operador <code>+=</code> para <dfn>concatenar</dfn> uma string no final de uma variável de string existente. Isso pode ser muito útil para quebrar uma longa cadeia ao longo de várias linhas. <strong>Nota</strong> <br> Cuidado com os espaços. A concatenação não adiciona espaços entre as sequências concatenadas, portanto, você precisará adicioná-las você mesmo. </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Crie <code>myStr</code> em várias linhas concatenando essas duas strings: <code>"This is the first sentence. "</code> e <code>"This is the second sentence."</code> usando o operador <code>+=</code> . Use o operador <code>+=</code> semelhante ao mostrado no editor. Comece atribuindo a primeira string ao <code>myStr</code> , em seguida, adicione a segunda string. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>myStr</code> deve ter um valor de <code>This is the first sentence. This is the second sentence.</code>
|
||||
testString: 'assert(myStr === "This is the first sentence. This is the second sentence.", "<code>myStr</code> should have a value of <code>This is the first sentence. This is the second sentence.</code>");'
|
||||
- text: Use o operador <code>+=</code> para construir <code>myStr</code>
|
||||
testString: 'assert(code.match(/\w\s*\+=\s*[""]/g).length > 1 && code.match(/\w\s*\=\s*[""]/g).length > 1, "Use the <code>+=</code> operator to build <code>myStr</code>");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var ourStr = "I come first. ";
|
||||
ourStr += "I come second.";
|
||||
|
||||
// Only change code below this line
|
||||
|
||||
var myStr;
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,65 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244b9
|
||||
title: Constructing Strings with Variables
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Construindo Strings com Variáveis
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Às vezes você precisará construir uma string, estilo <a href="https://en.wikipedia.org/wiki/Mad_Libs" target="_blank">Mad Libs</a> . Usando o operador de concatenação ( <code>+</code> ), você pode inserir uma ou mais variáveis em uma string que está construindo. </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Definir <code>myName</code> para uma string igual ao seu nome e construir <code>myStr</code> com <code>myName</code> entre as seqüências de caracteres <code>"My name is "</code> e <code>" and I am well!"</code> </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>myName</code> deve ser definido para uma string com pelo menos 3 caracteres
|
||||
testString: 'assert(typeof myName !== "undefined" && myName.length > 2, "<code>myName</code> should be set to a string at least 3 characters long");'
|
||||
- text: Use dois <code>+</code> operadores para construir <code>myStr</code> com <code>myName</code> dentro dele
|
||||
testString: 'assert(code.match(/[""]\s*\+\s*myName\s*\+\s*[""]/g).length > 0, "Use two <code>+</code> operators to build <code>myStr</code> with <code>myName</code> inside it");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var ourName = "freeCodeCamp";
|
||||
var ourStr = "Hello, our name is " + ourName + ", how are you?";
|
||||
|
||||
// Only change code below this line
|
||||
var myName;
|
||||
var myStr;
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,71 +0,0 @@
|
||||
---
|
||||
id: 56105e7b514f539506016a5e
|
||||
title: Count Backwards With a For Loop
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Conte para trás com um loop for
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Um loop for também pode contar para trás, desde que possamos definir as condições certas. Para contar para trás por dois, precisaremos alterar nossa <code>initialization</code> , <code>condition</code> e <code>final-expression</code> . Vamos começar em <code>i = 10</code> e fazer um loop enquanto <code>i > 0</code> . Diminuiremos <code>i</code> por 2 cada loop com <code>i -= 2</code> . <blockquote> var ourArray = []; <br> para (var i = 10; i> 0; i- = 2) { <br> ourArray.push (i); <br> } </blockquote> <code>ourArray</code> agora conterá <code>[10,8,6,4,2]</code> . Vamos alterar nossa <code>initialization</code> e <code>final-expression</code> para que possamos contar para trás por dois por números ímpares. </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Empurre os números ímpares de 9 a 1 para <code>myArray</code> usando um loop <code>for</code> . </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Você deve estar usando um <code>for</code> loop para isso.
|
||||
testString: 'assert(code.match(/for\s*\(/g).length > 1, "You should be using a <code>for</code> loop for this.");'
|
||||
- text: Você deve estar usando o método de matriz <code>push</code> .
|
||||
testString: 'assert(code.match(/myArray.push/), "You should be using the array method <code>push</code>.");'
|
||||
- text: '<code>myArray</code> deve ser igual a <code>[9,7,5,3,1]</code> .'
|
||||
testString: 'assert.deepEqual(myArray, [9,7,5,3,1], "<code>myArray</code> should equal <code>[9,7,5,3,1]</code>.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var ourArray = [];
|
||||
|
||||
for (var i = 10; i > 0; i -= 2) {
|
||||
ourArray.push(i);
|
||||
}
|
||||
|
||||
// Setup
|
||||
var myArray = [];
|
||||
|
||||
// Only change code below this line.
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,74 +0,0 @@
|
||||
---
|
||||
id: 565bbe00e9cc8ac0725390f4
|
||||
title: Counting Cards
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Contando Cartões
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> No jogo de cassino Blackjack, um jogador pode ganhar uma vantagem sobre a casa, mantendo o controle do número relativo de cartas altas e baixas remanescentes no baralho. Isso é chamado <a href="https://en.wikipedia.org/wiki/Card_counting" target="_blank">de contagem de cartão</a> . Ter mais cartas altas restantes no baralho favorece o jogador. Cada cartão recebe um valor de acordo com a tabela abaixo. Quando a contagem é positiva, o jogador deve apostar alto. Quando a contagem é zero ou negativa, o jogador deve apostar baixo. <table class="table table-striped"><thead><tr><th> Mudança de contagem </th><th> Postais </th></tr></thead><tbody><tr><td> +1 </td><td> 2, 3, 4, 5, 6 </td></tr><tr><td> 0 </td><td> 7, 8, 9 </td></tr><tr><td> -1 </td><td> 10, 'J', 'Q', 'K', 'A' </td></tr></tbody></table> Você vai escrever uma função de contagem de cartões. Ele receberá um parâmetro de <code>card</code> , que pode ser um número ou uma sequência, e incrementará ou decrementará a variável de <code>count</code> global de acordo com o valor da carta (consulte a tabela). A função retornará uma string com a contagem atual e a string <code>Bet</code> se a contagem for positiva ou <code>Hold</code> se a contagem for zero ou negativa. A contagem atual e a decisão do jogador ( <code>Bet</code> ou <code>Hold</code> ) devem ser separadas por um único espaço. <strong>Exemplo de saída</strong> <br> <code>-3 Hold</code> <br> <code>5 Bet</code> <strong>dica de</strong> <code>5 Bet</code> <br> NÃO redefina a <code>count</code> para 0 quando o valor for 7, 8 ou 9. <br> NÃO retorne um array. <br> NÃO inclua aspas (simples ou dupla) na saída. </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: 'Seqüência de Cartões 2, 3, 4, 5, 6 deve retornar <code>5 Bet</code>'
|
||||
testString: 'assert((function(){ count = 0; cc(2);cc(3);cc(4);cc(5);var out = cc(6); if(out === "5 Bet") {return true;} return false; })(), "Cards Sequence 2, 3, 4, 5, 6 should return <code>5 Bet</code>");'
|
||||
- text: 'Seqüência de Cartões 7, 8, 9 deve retornar <code>0 Hold</code>'
|
||||
testString: 'assert((function(){ count = 0; cc(7);cc(8);var out = cc(9); if(out === "0 Hold") {return true;} return false; })(), "Cards Sequence 7, 8, 9 should return <code>0 Hold</code>");'
|
||||
- text: 'Seqüência de cartas 10, J, Q, K, A deve retornar <code>-5 Hold</code>'
|
||||
testString: 'assert((function(){ count = 0; cc(10);cc("J");cc("Q");cc("K");var out = cc("A"); if(out === "-5 Hold") {return true;} return false; })(), "Cards Sequence 10, J, Q, K, A should return <code>-5 Hold</code>");'
|
||||
- text: 'Seqüência de Cartões 3, 7, Q, 8, A deve retornar <code>-1 Hold</code>'
|
||||
testString: 'assert((function(){ count = 0; cc(3);cc(7);cc("Q");cc(8);var out = cc("A"); if(out === "-1 Hold") {return true;} return false; })(), "Cards Sequence 3, 7, Q, 8, A should return <code>-1 Hold</code>");'
|
||||
- text: 'Cartas Sequência 2, J, 9, 2, 7 devem retornar <code>1 Bet</code>'
|
||||
testString: 'assert((function(){ count = 0; cc(2);cc("J");cc(9);cc(2);var out = cc(7); if(out === "1 Bet") {return true;} return false; })(), "Cards Sequence 2, J, 9, 2, 7 should return <code>1 Bet</code>");'
|
||||
- text: 'Seqüência de Cartões 2, 2, 10 deve retornar <code>1 Bet</code>'
|
||||
testString: 'assert((function(){ count = 0; cc(2);cc(2);var out = cc(10); if(out === "1 Bet") {return true;} return false; })(), "Cards Sequence 2, 2, 10 should return <code>1 Bet</code>");'
|
||||
- text: 'Seqüência de cartas 3, 2, A, 10, K deve retornar <code>-1 Hold</code>'
|
||||
testString: 'assert((function(){ count = 0; cc(3);cc(2);cc("A");cc(10);var out = cc("K"); if(out === "-1 Hold") {return true;} return false; })(), "Cards Sequence 3, 2, A, 10, K should return <code>-1 Hold</code>");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
var count = 0;
|
||||
|
||||
function cc(card) {
|
||||
// Only change code below this line
|
||||
|
||||
|
||||
return "Change Me";
|
||||
// Only change code above this line
|
||||
}
|
||||
|
||||
// Add/remove calls to test your function.
|
||||
// Note: Only the last will display
|
||||
cc(2); cc(3); cc(7); cc('K'); cc('A');
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,61 +0,0 @@
|
||||
---
|
||||
id: cf1391c1c11feddfaeb4bdef
|
||||
title: Create Decimal Numbers with JavaScript
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Crie números decimais com JavaScript
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Podemos também armazenar números decimais em variáveis. Números decimais às vezes são chamados de números de <dfn>ponto flutuante</dfn> ou <dfn>flutuantes</dfn> . <strong>Nota</strong> <br> Nem todos os números reais podem ser representados com precisão em <dfn>ponto flutuante</dfn> . Isso pode levar a erros de arredondamento. <a href="https://en.wikipedia.org/wiki/Floating_point#Accuracy_problems" target="_blank">Detalhes aqui</a> . </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Crie uma variável <code>myDecimal</code> e dê a ela um valor decimal com uma parte fracionária (por exemplo, <code>5.7</code> ). </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>myDecimal</code> deve ser um número.
|
||||
testString: 'assert(typeof myDecimal === "number", "<code>myDecimal</code> should be a number.");'
|
||||
- text: <code>myDecimal</code> deve ter um ponto decimal
|
||||
testString: 'assert(myDecimal % 1 != 0, "<code>myDecimal</code> should have a decimal point"); '
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
var ourDecimal = 5.7;
|
||||
|
||||
// Only change code below this line
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,60 +0,0 @@
|
||||
---
|
||||
id: bd7123c9c443eddfaeb5bdef
|
||||
title: Declare JavaScript Variables
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Declarar variáveis JavaScript
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Na ciência da computação, os <dfn>dados</dfn> são tudo o que é significativo para o computador. JavaScript fornece sete <dfn>tipos de dados</dfn> diferentes que são <code>undefined</code> , <code>null</code> , <code>boolean</code> , <code>string</code> , <code>symbol</code> , <code>number</code> e <code>object</code> . Por exemplo, os computadores distinguem entre números, como o número <code>12</code> , e <code>strings</code> , como <code>"12"</code> , <code>"dog"</code> ou <code>"123 cats"</code> , que são conjuntos de caracteres. Os computadores podem realizar operações matemáticas em um número, mas não em uma string. <dfn>As variáveis</dfn> permitem que os computadores armazenem e manipulem dados de maneira dinâmica. Eles fazem isso usando um "rótulo" para apontar os dados em vez de usar os dados em si. Qualquer um dos sete tipos de dados pode ser armazenado em uma variável. <code>Variables</code> são semelhantes às variáveis x e y que você usa em matemática, o que significa que elas são um nome simples para representar os dados aos quais queremos nos referir. As <code>variables</code> computador diferem das variáveis matemáticas, pois podem armazenar valores diferentes em momentos diferentes. Dizemos ao JavaScript para criar ou <dfn>declarar</dfn> uma variável colocando a palavra-chave <code>var</code> na frente dela, assim: <blockquote> var ourName; </blockquote> cria uma <code>variable</code> chamada <code>ourName</code> . Em JavaScript, terminamos as instruções com ponto e vírgula. <code>Variable</code> nomes das <code>Variable</code> podem ser constituídos por números, letras e <code>$</code> ou <code>_</code> , mas não podem conter espaços nem iniciar com um número. </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Use a palavra-chave <code>var</code> para criar uma variável chamada <code>myName</code> . <strong>Sugestão</strong> <br> Olhe para o exemplo <code>ourName</code> se você ficar preso. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: 'Você deve declarar <code>myName</code> com a palavra-chave <code>var</code> , terminando com um ponto-e-vírgula'
|
||||
testString: 'assert(/var\s+myName\s*;/.test(code), "You should declare <code>myName</code> with the <code>var</code> keyword, ending with a semicolon");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var ourName;
|
||||
|
||||
// Declare myName below this line
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,63 +0,0 @@
|
||||
---
|
||||
id: bd7123c9c444eddfaeb5bdef
|
||||
title: Declare String Variables
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Declarar Variáveis de Cadeia
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Anteriormente, usamos o código <code>var myName = "your name";</code> <code>"your name"</code> é chamado <dfn>literal de</dfn> <dfn>string</dfn> . É uma string porque é uma série de zero ou mais caracteres entre aspas simples ou duplas. </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Crie duas novas variáveis de <code>string</code> : <code>myFirstName</code> e <code>myLastName</code> e atribua a elas os valores de seu primeiro e último nome, respectivamente. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>myFirstName</code> deve ser uma string com pelo menos um caractere.
|
||||
testString: 'assert((function(){if(typeof myFirstName !== "undefined" && typeof myFirstName === "string" && myFirstName.length > 0){return true;}else{return false;}})(), "<code>myFirstName</code> should be a string with at least one character in it.");'
|
||||
- text: <code>myLastName</code> deve ser uma string com pelo menos um caractere.
|
||||
testString: 'assert((function(){if(typeof myLastName !== "undefined" && typeof myLastName === "string" && myLastName.length > 0){return true;}else{return false;}})(), "<code>myLastName</code> should be a string with at least one character in it.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var firstName = "Alan";
|
||||
var lastName = "Turing";
|
||||
|
||||
// Only change code below this line
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,66 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244ad
|
||||
title: Decrement a Number with JavaScript
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Decrementar um número com JavaScript
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Você pode facilmente <dfn>decrementar</dfn> ou diminuir uma variável por um com o operador <code>--</code> . <code>i--;</code> é o equivalente de <code>i = i - 1;</code> <strong>Nota</strong> <br> A linha inteira se torna <code>i--;</code> , eliminando a necessidade do sinal de igual. </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Altere o código para usar o operador <code>--</code> em <code>myVar</code> . </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>myVar</code> deve ser igual a <code>10</code>
|
||||
testString: 'assert(myVar === 10, "<code>myVar</code> should equal <code>10</code>");'
|
||||
- text: <code>myVar = myVar - 1;</code> deve ser mudado
|
||||
testString: 'assert(/var\s*myVar\s*=\s*11;\s*\/*.*\s*([-]{2}\s*myVar|myVar\s*[-]{2});/.test(code), "<code>myVar = myVar - 1;</code> should be changed");'
|
||||
- text: Use o <code>--</code> operador em <code>myVar</code>
|
||||
testString: 'assert(/[-]{2}\s*myVar|myVar\s*[-]{2}/.test(code), "Use the <code>--</code> operator on <code>myVar</code>");'
|
||||
- text: Não mude o código acima da linha
|
||||
testString: 'assert(/var myVar = 11;/.test(code), "Do not change code above the line");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
var myVar = 11;
|
||||
|
||||
// Only change code below this line
|
||||
myVar = myVar - 1;
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,79 +0,0 @@
|
||||
---
|
||||
id: 56bbb991ad1ed5201cd392d3
|
||||
title: Delete Properties from a JavaScript Object
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Excluir propriedades de um objeto JavaScript
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Também podemos excluir propriedades de objetos como este: <code>delete ourDog.bark;</code> </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Exclua a propriedade <code>"tails"</code> do <code>myDog</code> . Você pode usar a notação de pontos ou colchetes. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Exclua a propriedade <code>"tails"</code> do <code>myDog</code> .
|
||||
testString: 'assert(typeof myDog === "object" && myDog.tails === undefined, "Delete the property <code>"tails"</code> from <code>myDog</code>.");'
|
||||
- text: Não modifique a configuração do <code>myDog</code>
|
||||
testString: 'assert(code.match(/"tails": 1/g).length > 1, "Do not modify the <code>myDog</code> setup");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var ourDog = {
|
||||
"name": "Camper",
|
||||
"legs": 4,
|
||||
"tails": 1,
|
||||
"friends": ["everything!"],
|
||||
"bark": "bow-wow"
|
||||
};
|
||||
|
||||
delete ourDog.bark;
|
||||
|
||||
// Setup
|
||||
var myDog = {
|
||||
"name": "Happy Coder",
|
||||
"legs": 4,
|
||||
"tails": 1,
|
||||
"friends": ["freeCodeCamp Campers"],
|
||||
"bark": "woof"
|
||||
};
|
||||
|
||||
// Only change code below this line.
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,61 +0,0 @@
|
||||
---
|
||||
id: bd7993c9ca9feddfaeb7bdef
|
||||
title: Divide One Decimal by Another with JavaScript
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Divide um decimal por outro com JavaScript
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Agora vamos dividir um decimal por outro. </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Altere o valor <code>0.0</code> para que o <code>quotient</code> seja igual a <code>2.2</code> . </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: O <code>quotient</code> variável deve ser igual a <code>2.2</code>
|
||||
testString: 'assert(quotient === 2.2, "The variable <code>quotient</code> should equal <code>2.2</code>");'
|
||||
- text: Você deve usar o operador <code>/</code> para dividir 4.4 por 2
|
||||
testString: 'assert(/4\.40*\s*\/\s*2\.*0*/.test(code), "You should use the <code>/</code> operator to divide 4.4 by 2");'
|
||||
- text: A variável quociente deve ser atribuída apenas uma vez
|
||||
testString: 'assert(code.match(/quotient/g).length === 1, "The quotient variable should only be assigned once");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
var quotient = 0.0 / 2.0; // Fix this line
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,59 +0,0 @@
|
||||
---
|
||||
id: cf1111c1c11feddfaeb6bdef
|
||||
title: Divide One Number by Another with JavaScript
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Divide um número por outro com JavaScript
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Nós também podemos dividir um número por outro. JavaScript usa o símbolo <code>/</code> para divisão. <p> <strong>Exemplo</strong> </p><blockquote> myVar = 16/2; // atribuído 8 </blockquote></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Altere <code>0</code> para que o <code>quotient</code> seja igual a <code>2</code> . </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Faça o <code>quotient</code> variável igual a 2.
|
||||
testString: 'assert(quotient === 2, "Make the variable <code>quotient</code> equal to 2.");'
|
||||
- text: Use o operador <code>/</code>
|
||||
testString: 'assert(/\d+\s*\/\s*\d+/.test(code), "Use the <code>/</code> operator");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
var quotient = 66 / 0;
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,67 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244b6
|
||||
title: Escape Sequences in Strings
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Seqüências de escape em seqüências de caracteres
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Aspas não são os únicos caracteres que podem ser <dfn>escapados</dfn> dentro de uma string. Há dois motivos para usar caracteres de escape: o primeiro é permitir que você use caracteres que talvez não fossem capazes de digitar, como um backspace. Segundo, permitir que você represente várias aspas em uma string sem que o JavaScript interprete erroneamente o que você quer dizer. Nós aprendemos isso no desafio anterior. <table class="table table-striped"><thead><tr><th> Código </th><th> Saída </th></tr></thead><tbody><tr><td> <code>\'</code> </td> <td> citação única </td></tr><tr><td> <code>\"</code> </td> <td> citação dupla </td></tr><tr><td> <code>\\</code> </td> <td> barra invertida </td></tr><tr><td> <code>\n</code> </td> <td> nova linha </td></tr><tr><td> <code>\r</code> </td> <td> retorno de carro </td></tr><tr><td> <code>\t</code> </td> <td> aba </td></tr><tr><td> <code>\b</code> </td> <td> backspace </td></tr><tr><td> <code>\f</code> </td> <td> feed de formulário </td></tr></tbody></table> <em>Observe que a própria barra invertida deve ter o escape para ser exibida como uma barra invertida.</em> </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Atribuir as seguintes três linhas de texto para a única variável <code>myStr</code> usando seqüências de escape. <blockquote> Primeira linha <br> \Segunda linha <br> ThirdLine </blockquote> Você precisará usar seqüências de escape para inserir caracteres especiais corretamente. Você também precisará seguir o espaçamento como aparece acima, sem espaços entre seqüências de escape ou palavras. Aqui está o texto com as seqüências de escape escritas. <q>FirstLine <code>newline</code> <code>tab</code> <code>backslash</code> SecondLine <code>newline</code> ThirdLine</q> </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>myStr</code> não deve conter espaços
|
||||
testString: 'assert(!/ /.test(myStr), "<code>myStr</code> should not contain any spaces");'
|
||||
- text: '<code>myStr</code> deve conter as strings <code>FirstLine</code> , <code>SecondLine</code> e <code>ThirdLine</code> (lembre-se de <code>ThirdLine</code> maiúsculas e minúsculas)'
|
||||
testString: 'assert(/FirstLine/.test(myStr) && /SecondLine/.test(myStr) && /ThirdLine/.test(myStr), "<code>myStr</code> should contain the strings <code>FirstLine</code>, <code>SecondLine</code> and <code>ThirdLine</code> (remember case sensitivity)");'
|
||||
- text: <code>FirstLine</code> deve ser seguido pelo caractere de nova linha <code>\n</code>
|
||||
testString: 'assert(/FirstLine\n/.test(myStr), "<code>FirstLine</code> should be followed by the newline character <code>\n</code>");'
|
||||
- text: <code>myStr</code> deve conter um caractere de tabulação <code>\t</code> que segue um caractere de nova linha
|
||||
testString: 'assert(/\n\t/.test(myStr), "<code>myStr</code> should contain a tab character <code>\t</code> which follows a newline character");'
|
||||
- text: <code>SecondLine</code> deve ser precedido pelo caractere de barra invertida <code>\\</code>
|
||||
testString: 'assert(/\SecondLine/.test(myStr), "<code>SecondLine</code> should be preceded by the backslash character <code>\\</code>");'
|
||||
- text: Deve haver um caractere de nova linha entre o <code>SecondLine</code> e o <code>ThirdLine</code>
|
||||
testString: 'assert(/SecondLine\nThirdLine/.test(myStr), "There should be a newline character between <code>SecondLine</code> and <code>ThirdLine</code>");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
var myStr; // Change this line
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,59 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244b5
|
||||
title: Escaping Literal Quotes in Strings
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Escapando citações literais em cordas
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Quando você está definindo uma string, você deve começar e terminar com uma aspa simples ou dupla. O que acontece quando você precisa de uma citação literal: <code>"</code> ou <code>'</code> ? Interior de sua corda Em JavaScript, você pode <dfn>escapar de</dfn> uma citação de considerá-lo como um fim de citação corda, colocando uma <dfn>barra invertida</dfn> ( <code>\</code> ) em frente à cotação. <code>var sampleStr = "Alan said, \"Peter is learning JavaScript\".";</code> Isso sinaliza para o JavaScript que a seguinte citação não é o fim da string, mas deve aparecer dentro da string. Então, se você fosse imprimir isso no console, você teria: <code>Alan said, "Peter is learning JavaScript".</code> </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Use <dfn>barras invertidas</dfn> para atribuir uma string à variável <code>myStr</code> , de modo que, se você fosse imprimi-la no console, veria: <code>I am a "double quoted" string inside "double quotes".</code> </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Você deve usar duas aspas duplas ( <code>"</code> ) e quatro aspas duplas com escape ( <code>\"</code> ).
|
||||
testString: 'assert(code.match(/\\"/g).length === 4 && code.match(/[^\\]"/g).length === 2, "You should use two double quotes (<code>"</code>) and four escaped double quotes (<code>\"</code>).");'
|
||||
- text: 'Variável myStr deve conter a string: <code>I am a "double quoted" string inside "double quotes".</code>'
|
||||
testString: 'assert(myStr === "I am a \"double quoted\" string inside \"double quotes\".", "Variable myStr should contain the string: <code>I am a "double quoted" string inside "double quotes".</code>");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
var myStr = ""; // Change this line
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,71 +0,0 @@
|
||||
---
|
||||
id: bd7123c9c448eddfaeb5bdef
|
||||
title: Find the Length of a String
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Encontre o comprimento de uma string
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Você pode encontrar o comprimento de um valor de <code>String</code> escrevendo <code>.length</code> após a variável de string ou string literal. <code>"Alan Peter".length; // 10</code> Por exemplo, se <code>var firstName = "Charles"</code> uma variável <code>var firstName = "Charles"</code> , poderemos descobrir quanto tempo a string <code>"Charles"</code> está usando a propriedade <code>firstName.length</code> . </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Use a propriedade <code>.length</code> para contar o número de caracteres na variável <code>lastName</code> e atribuí-la a <code>lastNameLength</code> . </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>lastNameLength</code> deve ser igual a oito.
|
||||
testString: 'assert((function(){if(typeof lastNameLength !== "undefined" && typeof lastNameLength === "number" && lastNameLength === 8){return true;}else{return false;}})(), "<code>lastNameLength</code> should be equal to eight.");'
|
||||
- text: 'Você deve obter o comprimento de <code>lastName</code> usando <code>.length</code> como este: <code>lastName.length</code> .'
|
||||
testString: 'assert((function(){if(code.match(/\.length/gi) && code.match(/\.length/gi).length >= 2 && code.match(/var lastNameLength \= 0;/gi) && code.match(/var lastNameLength \= 0;/gi).length >= 1){return true;}else{return false;}})(), "You should be getting the length of <code>lastName</code> by using <code>.length</code> like this: <code>lastName.length</code>.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var firstNameLength = 0;
|
||||
var firstName = "Ada";
|
||||
|
||||
firstNameLength = firstName.length;
|
||||
|
||||
// Setup
|
||||
var lastNameLength = 0;
|
||||
var lastName = "Lovelace";
|
||||
|
||||
// Only change code below this line.
|
||||
|
||||
lastNameLength = lastName;
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,63 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244ae
|
||||
title: Finding a Remainder in JavaScript
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Encontrando um Restante em JavaScript
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> O operador <code>%</code> <dfn>restante</dfn> fornece o restante da divisão de dois números. <strong>Exemplo</strong> <blockquote> 5% 2 = 1 porque <br> Math.floor (5/2) = 2 (Quociente) <br> 2 * 2 = 4 <br> 5 - 4 = 1 (restante) </blockquote> <strong>Uso</strong> <br> Na matemática, um número pode ser verificado para ser par ou ímpar, verificando o restante da divisão do número por <code>2</code> . <blockquote> 17% 2 = 1 (17 é Ímpar) <br> 48% 2 = 0 (48 é mesmo) </blockquote> <strong>Nota</strong> <br> O operador <dfn>restante</dfn> é algumas vezes incorretamente chamado de operador "módulo". É muito semelhante ao módulo, mas não funciona corretamente com números negativos. </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Defina o <code>remainder</code> igual ao restante de <code>11</code> dividido por <code>3</code> usando o operador <dfn>restante</dfn> ( <code>%</code> ). </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: A variável <code>remainder</code> deve ser inicializada
|
||||
testString: 'assert(/var\s+?remainder/.test(code), "The variable <code>remainder</code> should be initialized");'
|
||||
- text: O valor do <code>remainder</code> deve ser <code>2</code>
|
||||
testString: 'assert(remainder === 2, "The value of <code>remainder</code> should be <code>2</code>");'
|
||||
- text: Você deve usar o operador <code>%</code>
|
||||
testString: 'assert(/\s+?remainder\s*?=\s*?.*%.*;/.test(code), "You should use the <code>%</code> operator");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Only change code below this line
|
||||
|
||||
var remainder;
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,68 +0,0 @@
|
||||
---
|
||||
id: cf1111c1c11feddfaeb9bdef
|
||||
title: Generate Random Fractions with JavaScript
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Gerar frações aleatórias com JavaScript
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Números aleatórios são úteis para criar um comportamento aleatório. JavaScript tem uma função <code>Math.random()</code> que gera um número decimal aleatório entre <code>0</code> (inclusive) e não chega a <code>1</code> (exclusivo). Assim <code>Math.random()</code> pode retornar um <code>0</code> mas nunca retorna um <code>1</code> <strong>Nota</strong> <br> Assim como <a href="/learn/javascript-algorithms-and-data-structures/basic-javascript/storing-values-with-the-assignment-operator" target="_blank">Armazenando Valores com o Operador Igual</a> , todas as chamadas de função serão resolvidas antes que o <code>return</code> executado, para que possamos <code>return</code> o valor da função <code>Math.random()</code> . </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Altere <code>randomFraction</code> para retornar um número aleatório em vez de retornar <code>0</code> . </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>randomFraction</code> deve retornar um número aleatório.
|
||||
testString: 'assert(typeof randomFraction() === "number", "<code>randomFraction</code> should return a random number.");'
|
||||
- text: O número retornado por <code>randomFraction</code> deve ser um decimal.
|
||||
testString: 'assert((randomFraction()+""). match(/\./g), "The number returned by <code>randomFraction</code> should be a decimal.");'
|
||||
- text: Você deve estar usando <code>Math.random</code> para gerar o número decimal aleatório.
|
||||
testString: 'assert(code.match(/Math\.random/g).length >= 0, "You should be using <code>Math.random</code> to generate the random decimal number.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function randomFraction() {
|
||||
|
||||
// Only change code below this line.
|
||||
|
||||
return 0;
|
||||
|
||||
// Only change code above this line.
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,70 +0,0 @@
|
||||
---
|
||||
id: cf1111c1c12feddfaeb1bdef
|
||||
title: Generate Random Whole Numbers with JavaScript
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Gere números inteiros aleatórios com JavaScript
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> É ótimo podermos gerar números decimais aleatórios, mas é ainda mais útil se usá-lo para gerar números inteiros aleatórios. <ol><li> Use <code>Math.random()</code> para gerar um decimal aleatório. </li><li> Multiplique esse decimal aleatório por <code>20</code> . </li><li> Use outra função, <code>Math.floor()</code> para arredondar o número para o número inteiro mais próximo. </li></ol> Lembre-se que <code>Math.random()</code> nunca pode retornar um <code>1</code> e, porque estamos arredondando para baixo, é impossível realmente obter <code>20</code> . Essa técnica nos dará um número inteiro entre <code>0</code> e <code>19</code> . Colocando tudo junto, é assim que nosso código se parece: <code>Math.floor(Math.random() * 20);</code> Estamos chamando <code>Math.random()</code> , multiplicando o resultado por 20, passando o valor para a função <code>Math.floor()</code> para arredondar o valor para o número inteiro mais próximo. </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Use essa técnica para gerar e retornar um número inteiro aleatório entre <code>0</code> e <code>9</code> . </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: O resultado de <code>randomWholeNum</code> deve ser um número inteiro.
|
||||
testString: 'assert(typeof randomWholeNum() === "number" && (function(){var r = randomWholeNum();return Math.floor(r) === r;})(), "The result of <code>randomWholeNum</code> should be a whole number.");'
|
||||
- text: Você deve estar usando <code>Math.random</code> para gerar um número aleatório.
|
||||
testString: 'assert(code.match(/Math.random/g).length > 1, "You should be using <code>Math.random</code> to generate a random number.");'
|
||||
- text: Você deve ter multiplicado o resultado de <code>Math.random</code> por 10 para torná-lo um número entre zero e nove.
|
||||
testString: 'assert(code.match(/\s*?Math.random\s*?\(\s*?\)\s*?\*\s*?10[\D]\s*?/g) || code.match(/\s*?10\s*?\*\s*?Math.random\s*?\(\s*?\)\s*?/g), "You should have multiplied the result of <code>Math.random</code> by 10 to make it a number that is between zero and nine.");'
|
||||
- text: Você deve usar <code>Math.floor</code> para remover a parte decimal do número.
|
||||
testString: 'assert(code.match(/Math.floor/g).length > 1, "You should use <code>Math.floor</code> to remove the decimal part of the number.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
var randomNumberBetween0and19 = Math.floor(Math.random() * 20);
|
||||
|
||||
function randomWholeNum() {
|
||||
|
||||
// Only change code below this line.
|
||||
|
||||
return Math.random();
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,80 +0,0 @@
|
||||
---
|
||||
id: cf1111c1c12feddfaeb2bdef
|
||||
title: Generate Random Whole Numbers within a Range
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Gerar números inteiros aleatórios dentro de um intervalo
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Em vez de gerar um número aleatório entre zero e um dado número, como fizemos antes, podemos gerar um número aleatório que esteja dentro de um intervalo de dois números específicos. Para fazer isso, definiremos um número mínimo <code>min</code> e um número máximo <code>max</code> . Aqui está a fórmula que vamos usar. Tome um momento para lê-lo e tente entender o que este código está fazendo: <code>Math.floor(Math.random() * (max - min + 1)) + min</code> </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Crie uma função chamada <code>randomRange</code> que <code>randomRange</code> um intervalo <code>myMin</code> e <code>myMax</code> e retorne um número aleatório que seja maior ou igual a <code>myMin</code> e seja menor ou igual a <code>myMax</code> , inclusive. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: 'O menor número aleatório que pode ser gerado por <code>randomRange</code> deve ser igual ao seu número mínimo, <code>myMin</code> .'
|
||||
testString: 'assert(calcMin === 5, "The lowest random number that can be generated by <code>randomRange</code> should be equal to your minimum number, <code>myMin</code>.");'
|
||||
- text: 'O maior número aleatório que pode ser gerado por <code>randomRange</code> deve ser igual ao seu número máximo, <code>myMax</code> .'
|
||||
testString: 'assert(calcMax === 15, "The highest random number that can be generated by <code>randomRange</code> should be equal to your maximum number, <code>myMax</code>.");'
|
||||
- text: 'O número aleatório gerado por <code>randomRange</code> deve ser um inteiro, não um decimal.'
|
||||
testString: 'assert(randomRange(0,1) % 1 === 0 , "The random number generated by <code>randomRange</code> should be an integer, not a decimal.");'
|
||||
- text: <code>randomRange</code> deve usar <code>myMax</code> e <code>myMin</code> e retornar um número aleatório no seu intervalo.
|
||||
testString: 'assert((function(){if(code.match(/myMax/g).length > 1 && code.match(/myMin/g).length > 2 && code.match(/Math.floor/g) && code.match(/Math.random/g)){return true;}else{return false;}})(), "<code>randomRange</code> should use both <code>myMax</code> and <code>myMin</code>, and return a random number in your range.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
function ourRandomRange(ourMin, ourMax) {
|
||||
|
||||
return Math.floor(Math.random() * (ourMax - ourMin + 1)) + ourMin;
|
||||
}
|
||||
|
||||
ourRandomRange(1, 9);
|
||||
|
||||
// Only change code below this line.
|
||||
|
||||
function randomRange(myMin, myMax) {
|
||||
|
||||
return 0; // Change this line
|
||||
|
||||
}
|
||||
|
||||
// Change these values to test your function
|
||||
var myRandom = randomRange(5, 15);
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,109 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244be
|
||||
title: Global Scope and Functions
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Âmbito global e funções
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Em JavaScript, o <dfn>escopo</dfn> se refere à visibilidade das variáveis. Variáveis definidas fora de um bloco de funções possuem escopo <dfn>Global</dfn> . Isso significa que eles podem ser vistos em qualquer lugar no seu código JavaScript. As variáveis que são usadas sem a palavra-chave <code>var</code> são criadas automaticamente no escopo <code>global</code> . Isso pode criar consequências indesejadas em outro lugar no seu código ou ao executar uma função novamente. Você deve sempre declarar suas variáveis com <code>var</code> . </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Usando <code>var</code> , declare uma variável <code>global</code> <code>myGlobal</code> fora de qualquer função. Inicialize com um valor de <code>10</code> . Dentro da função <code>fun1</code> , atribua <code>5</code> a <code>oopsGlobal</code> <strong><em>sem</em></strong> usar a palavra-chave <code>var</code> . </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>myGlobal</code> deve ser definido
|
||||
testString: 'assert(typeof myGlobal != "undefined", "<code>myGlobal</code> should be defined");'
|
||||
- text: <code>myGlobal</code> deve ter um valor de <code>10</code>
|
||||
testString: 'assert(myGlobal === 10, "<code>myGlobal</code> should have a value of <code>10</code>");'
|
||||
- text: <code>myGlobal</code> deve ser declarado usando a palavra-chave <code>var</code>
|
||||
testString: 'assert(/var\s+myGlobal/.test(code), "<code>myGlobal</code> should be declared using the <code>var</code> keyword");'
|
||||
- text: <code>oopsGlobal</code> deve ser uma variável global e ter um valor de <code>5</code>
|
||||
testString: 'assert(typeof oopsGlobal != "undefined" && oopsGlobal === 5, "<code>oopsGlobal</code> should be a global variable and have a value of <code>5</code>");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Declare your variable here
|
||||
|
||||
|
||||
function fun1() {
|
||||
// Assign 5 to oopsGlobal Here
|
||||
|
||||
}
|
||||
|
||||
// Only change code above this line
|
||||
function fun2() {
|
||||
var output = "";
|
||||
if (typeof myGlobal != "undefined") {
|
||||
output += "myGlobal: " + myGlobal;
|
||||
}
|
||||
if (typeof oopsGlobal != "undefined") {
|
||||
output += " oopsGlobal: " + oopsGlobal;
|
||||
}
|
||||
console.log(output);
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
### Before Test
|
||||
<div id='js-setup'>
|
||||
|
||||
```js
|
||||
var logOutput = "";
|
||||
var originalConsole = console
|
||||
function capture() {
|
||||
var nativeLog = console.log;
|
||||
console.log = function (message) {
|
||||
logOutput = message;
|
||||
if(nativeLog.apply) {
|
||||
nativeLog.apply(originalConsole, arguments);
|
||||
} else {
|
||||
var nativeMsg = Array.prototype.slice.apply(arguments).join(' ');
|
||||
nativeLog(nativeMsg);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function uncapture() {
|
||||
console.log = originalConsole.log;
|
||||
}
|
||||
var oopsGlobal;
|
||||
capture();
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,65 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244c0
|
||||
title: Global vs. Local Scope in Functions
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Escopo global vs. local em funções
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> É possível ter variáveis <dfn>locais</dfn> e <dfn>globais</dfn> com o mesmo nome. Quando você faz isso, a variável <code>local</code> tem precedência sobre a variável <code>global</code> . Neste exemplo: <blockquote> var someVar = "Chapéu"; <br> function myFun () { <br> var someVar = "Head"; <br> return someVar; <br> } </blockquote> A função <code>myFun</code> retornará <code>"Head"</code> porque a versão <code>local</code> da variável está presente. </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Adicione uma variável local à função <code>myOutfit</code> para substituir o valor de <code>outerWear</code> por <code>"sweater"</code> . </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Não altere o valor do <code>outerWear</code> global
|
||||
testString: 'assert(outerWear === "T-Shirt", "Do not change the value of the global <code>outerWear</code>");'
|
||||
- text: <code>myOutfit</code> deve retornar <code>"sweater"</code>
|
||||
testString: 'assert(myOutfit() === "sweater", "<code>myOutfit</code> should return <code>"sweater"</code>");'
|
||||
- text: Não altere a declaração de retorno
|
||||
testString: 'assert(/return outerWear/.test(code), "Do not change the return statement");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var outerWear = "T-Shirt";
|
||||
|
||||
function myOutfit() {
|
||||
// Only change code below this line
|
||||
|
||||
|
||||
|
||||
// Only change code above this line
|
||||
return outerWear;
|
||||
}
|
||||
|
||||
myOutfit();
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,80 +0,0 @@
|
||||
---
|
||||
id: 5664820f61c48e80c9fa476c
|
||||
title: Golf Code
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Código de Golfe
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> No jogo de <a href="https://en.wikipedia.org/wiki/Golf" target="_blank">golfe,</a> cada buraco tem um <code>par</code> significa o número médio de <code>strokes</code> um golfista deve fazer para afundar a bola em um buraco para completar a jogada. Dependendo de quão longe acima ou abaixo <code>par</code> seus <code>strokes</code> são, há um apelido diferente. Sua função receberá argumentos <code>par</code> e <code>strokes</code> . Retorna a string correta de acordo com esta tabela que lista os traços em ordem de prioridade; topo (maior) para baixo (menor): <table class="table table-striped"><thead><tr><th> Traços </th><th> Retorna </th></tr></thead><tbody><tr><td> 1 </td><td> "Buraco-em-um!" </td></tr><tr><td> <= par - 2 </td><td> "Águia" </td></tr><tr><td> par - 1 </td><td> "Passarinho" </td></tr><tr><td> par </td><td> "Par" </td></tr><tr><td> par + 1 </td><td> "Bogey" </td></tr><tr><td> par + 2 </td><td> "Bogey Duplo" </td></tr><tr><td> > par + 3 </td><td> "Ir para casa!" </td></tr></tbody></table> <code>par</code> e <code>strokes</code> serão sempre numéricos e positivos. Nós adicionamos uma matriz de todos os nomes para sua conveniência. </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: '<code>golfScore(4, 1)</code> deve retornar "Hole-in-one!"'
|
||||
testString: 'assert(golfScore(4, 1) === "Hole-in-one!", "<code>golfScore(4, 1)</code> should return "Hole-in-one!"");'
|
||||
- text: '<code>golfScore(4, 2)</code> deve retornar "Eagle"'
|
||||
testString: 'assert(golfScore(4, 2) === "Eagle", "<code>golfScore(4, 2)</code> should return "Eagle"");'
|
||||
- text: '<code>golfScore(5, 2)</code> deve retornar "Eagle"'
|
||||
testString: 'assert(golfScore(5, 2) === "Eagle", "<code>golfScore(5, 2)</code> should return "Eagle"");'
|
||||
- text: '<code>golfScore(4, 3)</code> deve retornar "Birdie"'
|
||||
testString: 'assert(golfScore(4, 3) === "Birdie", "<code>golfScore(4, 3)</code> should return "Birdie"");'
|
||||
- text: '<code>golfScore(4, 4)</code> deve retornar "Par"'
|
||||
testString: 'assert(golfScore(4, 4) === "Par", "<code>golfScore(4, 4)</code> should return "Par"");'
|
||||
- text: '<code>golfScore(1, 1)</code> deve retornar "Hole-in-one!"'
|
||||
testString: 'assert(golfScore(1, 1) === "Hole-in-one!", "<code>golfScore(1, 1)</code> should return "Hole-in-one!"");'
|
||||
- text: '<code>golfScore(5, 5)</code> deve retornar "Par"'
|
||||
testString: 'assert(golfScore(5, 5) === "Par", "<code>golfScore(5, 5)</code> should return "Par"");'
|
||||
- text: '<code>golfScore(4, 5)</code> deve retornar "Bogey"'
|
||||
testString: 'assert(golfScore(4, 5) === "Bogey", "<code>golfScore(4, 5)</code> should return "Bogey"");'
|
||||
- text: '<code>golfScore(4, 6)</code> deve retornar "Double Bogey"'
|
||||
testString: 'assert(golfScore(4, 6) === "Double Bogey", "<code>golfScore(4, 6)</code> should return "Double Bogey"");'
|
||||
- text: '<code>golfScore(4, 7)</code> deve retornar "Go Home!"'
|
||||
testString: 'assert(golfScore(4, 7) === "Go Home!", "<code>golfScore(4, 7)</code> should return "Go Home!"");'
|
||||
- text: '<code>golfScore(5, 9)</code> deve retornar "Go Home!"'
|
||||
testString: 'assert(golfScore(5, 9) === "Go Home!", "<code>golfScore(5, 9)</code> should return "Go Home!"");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
var names = ["Hole-in-one!", "Eagle", "Birdie", "Par", "Bogey", "Double Bogey", "Go Home!"];
|
||||
function golfScore(par, strokes) {
|
||||
// Only change code below this line
|
||||
|
||||
|
||||
return "Change Me";
|
||||
// Only change code above this line
|
||||
}
|
||||
|
||||
// Change these values to test
|
||||
golfScore(5, 4);
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,66 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244ac
|
||||
title: Increment a Number with JavaScript
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Incrementar um número com JavaScript
|
||||
---
|
||||
|
||||
## Descrição
|
||||
<section id="description"> Você pode facilmente <dfn>incrementar</dfn> ou adicionar mais um a uma variável com o operador <code>++</code> . <code>i++;</code> é o equivalente de <code>i = i + 1;</code> <strong>Nota</strong> <br> A linha inteira se torna <code>i++;</code> , eliminando a necessidade do sinal de igual. </section>
|
||||
|
||||
## Instruções
|
||||
<section id="instructions"> Altere o código para usar o operador <code>++</code> em <code>myVar</code> . <strong>Sugestão</strong> <br> Saiba mais sobre <a href="https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Increment_()" target="_blank">operadores aritméticos - Incremento (++)</a> . </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>myVar</code> deve ser igual a <code>88</code>
|
||||
testString: 'assert(myVar === 88, "<code>myVar</code> should equal <code>88</code>");'
|
||||
- text: <code>myVar = myVar + 1;</code> deve ser mudado
|
||||
testString: 'assert(/var\s*myVar\s*=\s*87;\s*\/*.*\s*([+]{2}\s*myVar|myVar\s*[+]{2});/.test(code), "<code>myVar = myVar + 1;</code> should be changed");'
|
||||
- text: Use o operador <code>++</code>
|
||||
testString: 'assert(/[+]{2}\s*myVar|myVar\s*[+]{2}/.test(code), "Use the <code>++</code> operator");'
|
||||
- text: Não mude o código acima da linha
|
||||
testString: 'assert(/var myVar = 87;/.test(code), "Do not change code above the line");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
var myVar = 87;
|
||||
|
||||
// Altere o código somente depois dessa linha.
|
||||
myVar = myVar + 1;
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solução
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// Solução necessária
|
||||
```
|
||||
</section>
|
@ -1,60 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244a9
|
||||
title: Initializing Variables with the Assignment Operator
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Inicializando Variáveis com o Operador de Atribuição
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> É comum <dfn>inicializar</dfn> uma variável com um valor inicial na mesma linha que é declarada. <code>var myVar = 0;</code> Cria uma nova variável chamada <code>myVar</code> e atribui a ela um valor inicial de <code>0</code> . </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Defina uma variável <code>a</code> com <code>var</code> e inicialize-a com um valor de <code>9</code> . </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Inicialize <code>a</code> para um valor de <code>9</code>
|
||||
testString: 'assert(/var\s+a\s*=\s*9\s*/.test(code), "Initialize <code>a</code> to a value of <code>9</code>");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var ourVar = 19;
|
||||
|
||||
// Only change code below this line
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,76 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244db
|
||||
title: Introducing Else If Statements
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Apresentando Else If Statements
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Se você tiver várias condições que precisam ser tratadas, você pode encadear instruções <code>if</code> junto com <code>else if</code> statements. <blockquote> if (num> 15) { <br> return "Maior que 15"; <br> } else if (num <5) { <br> return "Menor do que 5"; <br> } outro { <br> return "entre 5 e 15"; <br> } </blockquote></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Converta a lógica para usar <code>else if</code> statements. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Você deve ter pelo menos dois <code>else</code> declarações
|
||||
testString: 'assert(code.match(/else/g).length > 1, "You should have at least two <code>else</code> statements");'
|
||||
- text: Você deve ter pelo menos duas declarações <code>if</code>
|
||||
testString: 'assert(code.match(/if/g).length > 1, "You should have at least two <code>if</code> statements");'
|
||||
- text: Você deve fechar e abrir chaves para cada condição
|
||||
testString: 'assert(code.match(/if\s*\((.+)\)\s*\{[\s\S]+\}\s*else if\s*\((.+)\)\s*\{[\s\S]+\}\s*else\s*\{[\s\S]+\s*\}/), "You should have closing and opening curly braces for each condition in your if else statement");'
|
||||
- text: <code>testElseIf(0)</code> deve retornar "Menor que 5"
|
||||
testString: 'assert(testElseIf(0) === "Smaller than 5", "<code>testElseIf(0)</code> should return "Smaller than 5"");'
|
||||
- text: <code>testElseIf(5)</code> deve retornar "entre 5 e 10"
|
||||
testString: 'assert(testElseIf(5) === "Between 5 and 10", "<code>testElseIf(5)</code> should return "Between 5 and 10"");'
|
||||
- text: <code>testElseIf(7)</code> deve retornar "entre 5 e 10"
|
||||
testString: 'assert(testElseIf(7) === "Between 5 and 10", "<code>testElseIf(7)</code> should return "Between 5 and 10"");'
|
||||
- text: <code>testElseIf(10)</code> deve retornar "entre 5 e 10"
|
||||
testString: 'assert(testElseIf(10) === "Between 5 and 10", "<code>testElseIf(10)</code> should return "Between 5 and 10"");'
|
||||
- text: <code>testElseIf(12)</code> deve retornar "Maior que 10"
|
||||
testString: 'assert(testElseIf(12) === "Greater than 10", "<code>testElseIf(12)</code> should return "Greater than 10"");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function testElseIf(val) {
|
||||
if (val > 10) {
|
||||
return "Greater than 10";
|
||||
}
|
||||
|
||||
if (val < 5) {
|
||||
return "Smaller than 5";
|
||||
}
|
||||
|
||||
return "Between 5 and 10";
|
||||
}
|
||||
|
||||
// Change this value to test
|
||||
testElseIf(7);
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,78 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244da
|
||||
title: Introducing Else Statements
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Apresentando Else Statements
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Quando uma condição para uma declaração <code>if</code> for verdadeira, o bloco de código que a segue é executado. E quando essa condição é falsa? Normalmente nada aconteceria. Com uma instrução <code>else</code> , um bloco de código alternativo pode ser executado. <blockquote> if (num> 10) { <br> return "Maior que 10"; <br> } outro { <br> return "10 ou menos"; <br> } </blockquote></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Combine as instruções <code>if</code> em uma única instrução <code>if/else</code> . </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Você deve ter apenas uma declaração <code>if</code> no editor
|
||||
testString: 'assert(code.match(/if/g).length === 1, "You should only have one <code>if</code> statement in the editor");'
|
||||
- text: Você deveria usar uma instrução <code>else</code>
|
||||
testString: 'assert(/else/g.test(code), "You should use an <code>else</code> statement");'
|
||||
- text: <code>testElse(4)</code> deve retornar "5 ou menor"
|
||||
testString: 'assert(testElse(4) === "5 or Smaller", "<code>testElse(4)</code> should return "5 or Smaller"");'
|
||||
- text: <code>testElse(5)</code> deve retornar "5 ou menor"
|
||||
testString: 'assert(testElse(5) === "5 or Smaller", "<code>testElse(5)</code> should return "5 or Smaller"");'
|
||||
- text: <code>testElse(6)</code> deve retornar "maior que 5"
|
||||
testString: 'assert(testElse(6) === "Bigger than 5", "<code>testElse(6)</code> should return "Bigger than 5"");'
|
||||
- text: <code>testElse(10)</code> deve retornar "maior que 5"
|
||||
testString: 'assert(testElse(10) === "Bigger than 5", "<code>testElse(10)</code> should return "Bigger than 5"");'
|
||||
- text: Não mude o código acima ou abaixo das linhas.
|
||||
testString: 'assert(/var result = "";/.test(code) && /return result;/.test(code), "Do not change the code above or below the lines.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function testElse(val) {
|
||||
var result = "";
|
||||
// Only change code below this line
|
||||
|
||||
if (val > 5) {
|
||||
result = "Bigger than 5";
|
||||
}
|
||||
|
||||
if (val <= 5) {
|
||||
result = "5 or Smaller";
|
||||
}
|
||||
|
||||
// Only change code above this line
|
||||
return result;
|
||||
}
|
||||
|
||||
// Change this value to test
|
||||
testElse(4);
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,69 +0,0 @@
|
||||
---
|
||||
id: 56104e9e514f539506016a5c
|
||||
title: Iterate Odd Numbers With a For Loop
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Iterar números ímpares com um loop for
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Para laços não tem que iterar um de cada vez. Ao alterar nossa <code>final-expression</code> , podemos contar por números pares. Começaremos em <code>i = 0</code> e em loop enquanto <code>i < 10</code> . Vamos incrementar <code>i</code> por 2 cada loop com <code>i += 2</code> . <blockquote> var ourArray = []; <br> para (var i = 0; i <10; i + = 2) { <br> ourArray.push (i); <br> } </blockquote> <code>ourArray</code> irá agora conter <code>[0,2,4,6,8]</code> . Vamos mudar a nossa <code>initialization</code> para que possamos contar por números ímpares. </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Empurre os números ímpares de 1 a 9 para <code>myArray</code> usando um loop <code>for</code> . </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Você deve estar usando um <code>for</code> loop para isso.
|
||||
testString: 'assert(code.match(/for\s*\(/g).length > 1, "You should be using a <code>for</code> loop for this.");'
|
||||
- text: '<code>myArray</code> deve ser igual a <code>[1,3,5,7,9]</code> .'
|
||||
testString: 'assert.deepEqual(myArray, [1,3,5,7,9], "<code>myArray</code> should equal <code>[1,3,5,7,9]</code>.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var ourArray = [];
|
||||
|
||||
for (var i = 0; i < 10; i += 2) {
|
||||
ourArray.push(i);
|
||||
}
|
||||
|
||||
// Setup
|
||||
var myArray = [];
|
||||
|
||||
// Only change code below this line.
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,74 +0,0 @@
|
||||
---
|
||||
id: 5675e877dbd60be8ad28edc6
|
||||
title: Iterate Through an Array with a For Loop
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Iterar por meio de uma matriz com um loop for
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Uma tarefa comum em JavaScript é fazer uma iteração no conteúdo de uma matriz. Uma maneira de fazer isso é com um loop <code>for</code> . Este código irá mostrar cada elemento da array <code>arr</code> para o console: <blockquote> var arr = [10,9,8,7,6]; <br> para (var i = 0; i <arr.length; i ++) { <br> console.log (arr [i]); <br> } </blockquote> Lembre-se que os Arrays possuem numeração baseada em zero, o que significa que o último índice do array é length - 1. Nossa <dfn>condição</dfn> para este loop é <code>i < arr.length</code> , que para quando <code>i</code> tiver comprimento - 1. </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Declare e inicialize um <code>total</code> variáveis para <code>0</code> . Use um loop <code>for</code> para adicionar o valor de cada elemento da matriz <code>myArr</code> ao <code>total</code> . </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>total</code> deve ser declarado e inicializado para 0
|
||||
testString: 'assert(code.match(/var.*?total\s*=\s*0.*?;/), "<code>total</code> should be declared and initialized to 0");'
|
||||
- text: <code>total</code> deve ser igual a 20
|
||||
testString: 'assert(total === 20, "<code>total</code> should equal 20");'
|
||||
- text: Você deve usar um loop <code>for</code> para iterar pelo <code>myArr</code>
|
||||
testString: 'assert(code.match(/for\s*\(/g).length > 1 && code.match(/myArr\s*\[/), "You should use a <code>for</code> loop to iterate through <code>myArr</code>");'
|
||||
- text: Não defina o <code>total</code> para 20 diretamente
|
||||
testString: 'assert(!code.match(/total[\s\+\-]*=\s*(\d(?!\s*[;,])|[1-9])/g), "Do not set <code>total</code> to 20 directly");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var ourArr = [ 9, 10, 11, 12];
|
||||
var ourTotal = 0;
|
||||
|
||||
for (var i = 0; i < ourArr.length; i++) {
|
||||
ourTotal += ourArr[i];
|
||||
}
|
||||
|
||||
// Setup
|
||||
var myArr = [ 2, 3, 4, 5, 6];
|
||||
|
||||
// Only change code below this line
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,70 +0,0 @@
|
||||
---
|
||||
id: 5a2efd662fb457916e1fe604
|
||||
title: Iterate with JavaScript Do...While Loops
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Iterar com JavaScript Do ... While Loops
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Você pode executar o mesmo código várias vezes usando um loop. O próximo tipo de loop que você aprenderá é chamado de loop <code>do...while</code> porque primeiro ele <code>do</code> uma passagem do código dentro do loop, não importa o que aconteça, e então executa <code>while</code> uma condição especificada é verdadeira e pára assim que a condição não for mais verdadeira. Vamos ver um exemplo. <blockquote> var ourArray = []; <br> var i = 0; <br> Faz { <br> ourArray.push (i); <br> i ++; <br> } enquanto (i <5); </blockquote> Isso se comporta exatamente como você esperaria com qualquer outro tipo de loop, e a matriz resultante será semelhante a <code>[0, 1, 2, 3, 4]</code> . No entanto, o que faz o <code>do...while</code> diferente de outros loops é como ele se comporta quando a condição falha na primeira verificação. Vamos ver isso em ação. Aqui está um loop regular que executará o código no loop desde que <code>i < 5</code> . <blockquote> var ourArray = []; <br> var i = 5; <br> enquanto (i <5) { <br> ourArray.push (i); <br> i ++; <br> } </blockquote> Observe que inicializamos o valor de <code>i</code> como sendo 5. Quando executamos a próxima linha, notamos que <code>i</code> não é menor que 5. Portanto, não executamos o código dentro do loop. O resultado é que o <code>ourArray</code> terá nada adicionado a ele, então ele ainda ficará assim <code>[]</code> quando todo o código no exemplo acima terminar de ser executado. Agora, dê uma olhada em um <code>do...while</code> loop. <blockquote> var ourArray = []; <br> var i = 5; <br> Faz { <br> ourArray.push (i); <br> i ++; <br> } enquanto (i <5); </blockquote> Neste caso, inicializamos o valor de <code>i</code> como 5, assim como fizemos com o loop while. Quando chegamos à próxima linha, não há verificação para o valor de <code>i</code> , então vamos para o código dentro das chaves e executá-lo. Vamos adicionar um elemento à matriz e incrementar <code>i</code> antes de chegarmos à verificação de condição. Então, quando chegarmos a verificar se <code>i < 5</code> ver que <code>i</code> agora é 6, o que falha na verificação condicional. Então, saímos do loop e acabamos. No final do exemplo acima, o valor de <code>ourArray</code> é <code>[5]</code> . Essencialmente, um laço <code>do...while</code> while garante que o código dentro do loop será executado pelo menos uma vez. Vamos tentar fazer um <code>do...while</code> loop para trabalhar, empurrando valores para um array. </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Alterar o <code>while</code> loop no código a um <code>do...while</code> loop para que o loop vai empurrar o número 10 a <code>myArray</code> , e <code>i</code> será igual a <code>11</code> quando o código termina a execução. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Você deveria estar usando um <code>do...while</code> loop para isso.
|
||||
testString: 'assert(code.match(/do/g), "You should be using a <code>do...while</code> loop for this.");'
|
||||
- text: '<code>myArray</code> deve ser igual a <code>[10]</code> .'
|
||||
testString: 'assert.deepEqual(myArray, [10], "<code>myArray</code> should equal <code>[10]</code>.");'
|
||||
- text: <code>i</code> deveria igual a <code>11</code>
|
||||
testString: 'assert.deepEqual(i, 11, "<code>i</code> should equal <code>11</code>");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var myArray = [];
|
||||
var i = 10;
|
||||
|
||||
// Only change code below this line.
|
||||
|
||||
while (i < 5) {
|
||||
myArray.push(i);
|
||||
i++;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,69 +0,0 @@
|
||||
---
|
||||
id: cf1111c1c11feddfaeb5bdef
|
||||
title: Iterate with JavaScript For Loops
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Iterar com JavaScript For Loops
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Você pode executar o mesmo código várias vezes usando um loop. O tipo mais comum de loop de JavaScript é chamado de <code>for loop</code> porque é executado "por" um número específico de vezes. For loops são declarados com três expressões opcionais separadas por ponto e vírgula: <code>for ([initialization]; [condition]; [final-expression])</code> A instrução de <code>initialization</code> é executada uma vez apenas antes do loop iniciar. É normalmente usado para definir e configurar sua variável de loop. A instrução de <code>condition</code> é avaliada no início de cada iteração de loop e continuará enquanto ela for avaliada como <code>true</code> . Quando a <code>condition</code> é <code>false</code> no início da iteração, o loop deixará de ser executado. Isso significa que se a <code>condition</code> começar como <code>false</code> , seu loop nunca será executado. A <code>final-expression</code> é executada no final de cada iteração de loop, antes da próxima verificação de <code>condition</code> e é geralmente usada para incrementar ou decrementar seu contador de loop. No exemplo a seguir, inicializamos com <code>i = 0</code> e iteramos enquanto nossa condição <code>i < 5</code> é verdadeira. Vamos incrementar <code>i</code> por <code>1</code> em cada iteração de loop com o <code>i++</code> como nossa <code>final-expression</code> . <blockquote> var ourArray = []; <br> para (var i = 0; i <5; i ++) { <br> ourArray.push (i); <br> } </blockquote> <code>ourArray</code> irá agora conter <code>[0,1,2,3,4]</code> . </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Use um loop <code>for</code> para trabalhar para empurrar os valores de 1 a 5 para <code>myArray</code> . </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Você deve estar usando um <code>for</code> loop para isso.
|
||||
testString: 'assert(code.match(/for\s*\(/g).length > 1, "You should be using a <code>for</code> loop for this.");'
|
||||
- text: '<code>myArray</code> deve ser igual a <code>[1,2,3,4,5]</code> .'
|
||||
testString: 'assert.deepEqual(myArray, [1,2,3,4,5], "<code>myArray</code> should equal <code>[1,2,3,4,5]</code>.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var ourArray = [];
|
||||
|
||||
for (var i = 0; i < 5; i++) {
|
||||
ourArray.push(i);
|
||||
}
|
||||
|
||||
// Setup
|
||||
var myArray = [];
|
||||
|
||||
// Only change code below this line.
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,62 +0,0 @@
|
||||
---
|
||||
id: cf1111c1c11feddfaeb1bdef
|
||||
title: Iterate with JavaScript While Loops
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Iterar com loops While de JavaScript
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Você pode executar o mesmo código várias vezes usando um loop. O primeiro tipo de loop vamos aprender é chamado de <code>while</code> laço porque ele é executado "enquanto" uma condição especificada for verdadeira e pára uma vez que a condição já não é verdade. <blockquote> var ourArray = []; <br> var i = 0; <br> enquanto (i <5) { <br> ourArray.push (i); <br> i ++; <br> } </blockquote> Vamos tentar fazer um loop while funcionar empurrando valores para um array. </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Empurrar os números de 0 a 4 para <code>myArray</code> usando uma <code>while</code> loop. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Você deve estar usando um <code>while</code> loop para isso.
|
||||
testString: 'assert(code.match(/while/g), "You should be using a <code>while</code> loop for this.");'
|
||||
- text: '<code>myArray</code> deve ser igual a <code>[0,1,2,3,4]</code> .'
|
||||
testString: 'assert.deepEqual(myArray, [0,1,2,3,4], "<code>myArray</code> should equal <code>[0,1,2,3,4]</code>.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var myArray = [];
|
||||
|
||||
// Only change code below this line.
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,96 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244bf
|
||||
title: Local Scope and Functions
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Escopo Local e Funções
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Variáveis que são declaradas dentro de uma função, assim como os parâmetros da função, possuem escopo <dfn>local</dfn> . Isso significa que eles só são visíveis dentro dessa função. Aqui está uma função <code>myTest</code> com uma variável local chamada <code>loc</code> . <blockquote> function myTest () { <br> var loc = "foo"; <br> console.log (loc); <br> } <br> meu teste(); // registra "foo" <br> console.log (loc); // loc não está definido </blockquote> <code>loc</code> não está definido fora da função. </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Declare uma variável local <code>myVar</code> dentro de <code>myLocalScope</code> . Execute os testes e siga as instruções comentadas no editor. <strong>Sugestão</strong> <br> Atualizando a página pode ajudar se você ficar preso. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Nenhuma variável <code>myVar</code> global
|
||||
testString: 'assert(typeof myVar === "undefined", "No global <code>myVar</code> variable");'
|
||||
- text: Adicione uma variável <code>myVar</code> local
|
||||
testString: 'assert(/var\s+myVar/.test(code), "Add a local <code>myVar</code> variable");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function myLocalScope() {
|
||||
'use strict'; // you shouldn't need to edit this line
|
||||
|
||||
console.log(myVar);
|
||||
}
|
||||
myLocalScope();
|
||||
|
||||
// Run and check the console
|
||||
// myVar is not defined outside of myLocalScope
|
||||
console.log(myVar);
|
||||
|
||||
// Now remove the console log line to pass the test
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
### Before Test
|
||||
<div id='js-setup'>
|
||||
|
||||
```js
|
||||
var logOutput = "";
|
||||
var originalConsole = console
|
||||
function capture() {
|
||||
var nativeLog = console.log;
|
||||
console.log = function (message) {
|
||||
logOutput = message;
|
||||
if(nativeLog.apply) {
|
||||
nativeLog.apply(originalConsole, arguments);
|
||||
} else {
|
||||
var nativeMsg = Array.prototype.slice.apply(arguments).join(' ');
|
||||
nativeLog(nativeMsg);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function uncapture() {
|
||||
console.log = originalConsole.log;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,64 +0,0 @@
|
||||
---
|
||||
id: 5690307fddb111c6084545d7
|
||||
title: Logical Order in If Else Statements
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Ordem lógica em outras declarações
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Ordem é importante em <code>if</code> , <code>else if</code> declarações. A função é executada de cima para baixo, então você vai querer ter cuidado com a afirmação que vem primeiro. Tome estas duas funções como um exemplo. Aqui está o primeiro: <blockquote> função foo (x) { <br> if (x <1) { <br> return "menos de um"; <br> } else if (x <2) { <br> return "menos de dois"; <br> } outro { <br> return "Maior que ou igual a dois"; <br> } <br> } </blockquote> E o segundo apenas muda a ordem das declarações: <blockquote> barra de funções (x) { <br> if (x <2) { <br> return "menos de dois"; <br> } else if (x <1) { <br> return "menos de um"; <br> } outro { <br> return "Maior que ou igual a dois"; <br> } <br> } </blockquote> Embora essas duas funções pareçam quase idênticas, se passarmos um número para ambas, obteremos saídas diferentes. <blockquote> foo (0) // "Menos que um" <br> bar (0) // "menos de dois" </blockquote></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Altere a ordem da lógica na função para que ela retorne as instruções corretas em todos os casos. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>orderMyLogic(4)</code> deve retornar "Menos de 5"
|
||||
testString: 'assert(orderMyLogic(4) === "Less than 5", "<code>orderMyLogic(4)</code> should return "Less than 5"");'
|
||||
- text: <code>orderMyLogic(6)</code> deve retornar "Menor que 10"
|
||||
testString: 'assert(orderMyLogic(6) === "Less than 10", "<code>orderMyLogic(6)</code> should return "Less than 10"");'
|
||||
- text: <code>orderMyLogic(11)</code> deve retornar "maior que ou igual a 10"
|
||||
testString: 'assert(orderMyLogic(11) === "Greater than or equal to 10", "<code>orderMyLogic(11)</code> should return "Greater than or equal to 10"");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function orderMyLogic(val) {
|
||||
if (val < 10) {
|
||||
return "Less than 10";
|
||||
} else if (val < 5) {
|
||||
return "Less than 5";
|
||||
} else {
|
||||
return "Greater than or equal to 10";
|
||||
}
|
||||
}
|
||||
|
||||
// Change this value to test
|
||||
orderMyLogic(7);
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,70 +0,0 @@
|
||||
---
|
||||
id: 56bbb991ad1ed5201cd392cc
|
||||
title: Manipulate Arrays With pop()
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Manipular Arrays Com pop ()
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Outra maneira de alterar os dados em uma matriz é com a função <code>.pop()</code> . <code>.pop()</code> é usado para "pop" um valor fora do final de uma matriz. Podemos armazenar esse valor "popped off", atribuindo-o a uma variável. Em outras palavras, <code>.pop()</code> remove o último elemento de uma matriz e retorna esse elemento. Qualquer tipo de entrada pode ser "popped" fora de um array - números, strings, até matrizes aninhadas. <blockquote> <code>var threeArr = [1, 4, 6]; <br> var oneDown = threeArr.pop(); <br> console.log(oneDown); // Returns 6 <br> console.log(threeArr); // Returns [1, 4]</code> </blockquote> </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Use a função <code>.pop()</code> para remover o último item de <code>myArray</code> , atribuindo o valor "popped off" ao <code>removedFromMyArray</code> . </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: '<code>myArray</code> deve conter apenas <code>[["John", 23]]</code> .'
|
||||
testString: 'assert((function(d){if(d[0][0] == "John" && d[0][1] === 23 && d[1] == undefined){return true;}else{return false;}})(myArray), "<code>myArray</code> should only contain <code>[["John", 23]]</code>.");'
|
||||
- text: Use <code>pop()</code> no <code>myArray</code>
|
||||
testString: 'assert(/removedFromMyArray\s*=\s*myArray\s*.\s*pop\s*(\s*)/.test(code), "Use <code>pop()</code> on <code>myArray</code>");'
|
||||
- text: '<code>removedFromMyArray</code> deve conter apenas <code>["cat", 2]</code> .'
|
||||
testString: 'assert((function(d){if(d[0] == "cat" && d[1] === 2 && d[2] == undefined){return true;}else{return false;}})(removedFromMyArray), "<code>removedFromMyArray</code> should only contain <code>["cat", 2]</code>.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var ourArray = [1,2,3];
|
||||
var removedFromOurArray = ourArray.pop();
|
||||
// removedFromOurArray now equals 3, and ourArray now equals [1,2]
|
||||
|
||||
// Setup
|
||||
var myArray = [["John", 23], ["cat", 2]];
|
||||
|
||||
// Only change code below this line.
|
||||
var removedFromMyArray;
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,65 +0,0 @@
|
||||
---
|
||||
id: 56bbb991ad1ed5201cd392cb
|
||||
title: Manipulate Arrays With push()
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Manipular matrizes com push ()
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Uma maneira fácil de anexar dados ao final de um array é por meio da função <code>push()</code> . <code>.push()</code> recebe um ou mais <dfn>parâmetros</dfn> e os "empurra" para o final do array. <blockquote> var arr = [1,2,3]; <br> arr.push (4); <br> // arr é agora [1,2,3,4] </blockquote></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Empurre <code>["dog", 3]</code> para o final da variável <code>myArray</code> . </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: '<code>myArray</code> agora deve ser igual a <code>[["John", 23], ["cat", 2], ["dog", 3]]</code> .'
|
||||
testString: 'assert((function(d){if(d[2] != undefined && d[0][0] == "John" && d[0][1] === 23 && d[2][0] == "dog" && d[2][1] === 3 && d[2].length == 2){return true;}else{return false;}})(myArray), "<code>myArray</code> should now equal <code>[["John", 23], ["cat", 2], ["dog", 3]]</code>.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var ourArray = ["Stimpson", "J", "cat"];
|
||||
ourArray.push(["happy", "joy"]);
|
||||
// ourArray now equals ["Stimpson", "J", "cat", ["happy", "joy"]]
|
||||
|
||||
// Setup
|
||||
var myArray = [["John", 23], ["cat", 2]];
|
||||
|
||||
// Only change code below this line.
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,68 +0,0 @@
|
||||
---
|
||||
id: 56bbb991ad1ed5201cd392cd
|
||||
title: Manipulate Arrays With shift()
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Manipular Matrizes Com Deslocamento ()
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> <code>pop()</code> sempre remove o último elemento de um array. E se você quiser remover o primeiro? É aí que <code>.shift()</code> . Funciona exatamente como o <code>.pop()</code> , exceto que ele remove o primeiro elemento em vez do último. </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Use a função <code>.shift()</code> para remover o primeiro item de <code>myArray</code> , atribuindo o valor " <code>removedFromMyArray</code> off" ao <code>removedFromMyArray</code> . </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: '<code>myArray</code> agora deve ser igual a <code>[["dog", 3]]</code> .'
|
||||
testString: 'assert((function(d){if(d[0][0] == "dog" && d[0][1] === 3 && d[1] == undefined){return true;}else{return false;}})(myArray), "<code>myArray</code> should now equal <code>[["dog", 3]]</code>.");'
|
||||
- text: '<code>removedFromMyArray</code> deve conter <code>["John", 23]</code> .'
|
||||
testString: 'assert((function(d){if(d[0] == "John" && d[1] === 23 && typeof removedFromMyArray === "object"){return true;}else{return false;}})(removedFromMyArray), "<code>removedFromMyArray</code> should contain <code>["John", 23]</code>.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var ourArray = ["Stimpson", "J", ["cat"]];
|
||||
var removedFromOurArray = ourArray.shift();
|
||||
// removedFromOurArray now equals "Stimpson" and ourArray now equals ["J", ["cat"]].
|
||||
|
||||
// Setup
|
||||
var myArray = [["John", 23], ["dog", 3]];
|
||||
|
||||
// Only change code below this line.
|
||||
var removedFromMyArray;
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,67 +0,0 @@
|
||||
---
|
||||
id: 56bbb991ad1ed5201cd392ce
|
||||
title: Manipulate Arrays With unshift()
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Manipular matrizes com unshift ()
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Não apenas você pode <code>shift</code> elementos do início de um array, você também pode <code>unshift</code> elementos para o início de um array, isto é, adicionar elementos na frente do array. <code>.unshift()</code> funciona exatamente como <code>.push()</code> , mas em vez de adicionar o elemento no final da matriz, <code>unshift()</code> adiciona o elemento no início da matriz. </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Adicione <code>["Paul",35]</code> ao início da variável <code>myArray</code> usando <code>unshift()</code> . </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: '<code>myArray</code> agora deve ter [["Paul", 35], ["dog", 3]].'
|
||||
testString: 'assert((function(d){if(typeof d[0] === "object" && d[0][0] == "Paul" && d[0][1] === 35 && d[1][0] != undefined && d[1][0] == "dog" && d[1][1] != undefined && d[1][1] == 3){return true;}else{return false;}})(myArray), "<code>myArray</code> should now have [["Paul", 35], ["dog", 3]].");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var ourArray = ["Stimpson", "J", "cat"];
|
||||
ourArray.shift(); // ourArray now equals ["J", "cat"]
|
||||
ourArray.unshift("Happy");
|
||||
// ourArray now equals ["Happy", "J", "cat"]
|
||||
|
||||
// Setup
|
||||
var myArray = [["John", 23], ["dog", 3]];
|
||||
myArray.shift();
|
||||
|
||||
// Only change code below this line.
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,86 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244cb
|
||||
title: Manipulating Complex Objects
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Manipulando Objetos Complexos
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Às vezes você pode querer armazenar dados em uma <dfn>estrutura de dados</dfn> flexível. Um objeto JavaScript é uma maneira de lidar com dados flexíveis. Eles permitem combinações arbitrárias de <dfn>strings</dfn> , <dfn>números</dfn> , <dfn>booleanos</dfn> , <dfn>matrizes</dfn> , <dfn>funções</dfn> e <dfn>objetos</dfn> . Aqui está um exemplo de uma estrutura de dados complexa: <blockquote> var ourMusic = [ <br> { <br> "artista": "Daft Punk", <br> "title": "Homework", <br> "release_year": 1997, <br> "formatos": [ <br> "CD", <br> "Cassete", <br> "LP" <br> ] <br> "gold": true <br> } <br> ]; </blockquote> Esta é uma matriz que contém um objeto dentro. O objeto possui vários <dfn>metadados</dfn> sobre um álbum. Ele também possui uma matriz de <code>"formats"</code> aninhados. Se você quiser adicionar mais registros de álbuns, poderá fazer isso adicionando registros à matriz de nível superior. Objetos retêm dados em uma propriedade, que possui um formato de valor-chave. No exemplo acima, <code>"artist": "Daft Punk"</code> é uma propriedade que tem uma chave de <code>"artist"</code> e um valor de <code>"Daft Punk"</code> . <a href="http://www.json.org/" target="_blank">JavaScript Object Notation</a> ou <code>JSON</code> é um formato de intercâmbio de dados relacionado usado para armazenar dados. <blockquote> { <br> "artista": "Daft Punk", <br> "title": "Homework", <br> "release_year": 1997, <br> "formatos": [ <br> "CD", <br> "Cassete", <br> "LP" <br> ] <br> "gold": true <br> } </blockquote> <strong>Nota</strong> <br> Você precisará colocar uma vírgula após cada objeto na matriz, a menos que seja o último objeto na matriz. </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Adicione um novo álbum ao array <code>myMusic</code> . Adicione strings de <code>artist</code> e <code>title</code> , <code>release_year</code> number e uma matriz de <code>formats</code> de strings. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>myMusic</code> deve ser um array
|
||||
testString: 'assert(Array.isArray(myMusic), "<code>myMusic</code> should be an array");'
|
||||
- text: <code>myMusic</code> deve ter pelo menos dois elementos
|
||||
testString: 'assert(myMusic.length > 1, "<code>myMusic</code> should have at least two elements");'
|
||||
- text: '<code>myMusic[1]</code> deve ser um objeto'
|
||||
testString: 'assert(typeof myMusic[1] === "object", "<code>myMusic[1]</code> should be an object");'
|
||||
- text: '<code>myMusic[1]</code> deve ter pelo menos 4 propriedades'
|
||||
testString: 'assert(Object.keys(myMusic[1]).length > 3, "<code>myMusic[1]</code> should have at least 4 properties");'
|
||||
- text: '<code>myMusic[1]</code> deve conter uma propriedade de <code>artist</code> que seja uma string'
|
||||
testString: 'assert(myMusic[1].hasOwnProperty("artist") && typeof myMusic[1].artist === "string", "<code>myMusic[1]</code> should contain an <code>artist</code> property which is a string");'
|
||||
- text: '<code>myMusic[1]</code> deve conter uma propriedade de <code>title</code> que é uma string'
|
||||
testString: 'assert(myMusic[1].hasOwnProperty("title") && typeof myMusic[1].title === "string", "<code>myMusic[1]</code> should contain a <code>title</code> property which is a string");'
|
||||
- text: '<code>myMusic[1]</code> deve conter uma propriedade <code>release_year</code> que é um número'
|
||||
testString: 'assert(myMusic[1].hasOwnProperty("release_year") && typeof myMusic[1].release_year === "number", "<code>myMusic[1]</code> should contain a <code>release_year</code> property which is a number");'
|
||||
- text: '<code>myMusic[1]</code> deve conter uma propriedade de <code>formats</code> que é uma matriz'
|
||||
testString: 'assert(myMusic[1].hasOwnProperty("formats") && Array.isArray(myMusic[1].formats), "<code>myMusic[1]</code> should contain a <code>formats</code> property which is an array");'
|
||||
- text: <code>formats</code> devem ser um array de strings com pelo menos dois elementos
|
||||
testString: 'assert(myMusic[1].formats.every(function(item) { return (typeof item === "string")}) && myMusic[1].formats.length > 1, "<code>formats</code> should be an array of strings with at least two elements");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
var myMusic = [
|
||||
{
|
||||
"artist": "Billy Joel",
|
||||
"title": "Piano Man",
|
||||
"release_year": 1973,
|
||||
"formats": [
|
||||
"CD",
|
||||
"8T",
|
||||
"LP"
|
||||
],
|
||||
"gold": true
|
||||
}
|
||||
// Add record here
|
||||
];
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,66 +0,0 @@
|
||||
---
|
||||
id: cf1111c1c11feddfaeb8bdef
|
||||
title: Modify Array Data With Indexes
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Modificar dados de matriz com índices
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Ao contrário das strings, as entradas das matrizes são <dfn>mutáveis</dfn> e podem ser alteradas livremente. <strong>Exemplo</strong> <blockquote> var ourArray = [50,40,30]; <br> ourArray [0] = 15; // é igual a [15,40,30] </blockquote> <strong>Nota</strong> <br> Não deve haver espaços entre o nome da matriz e os colchetes, como <code>array [0]</code> . Embora JavaScript seja capaz de processar isso corretamente, isso pode confundir outros programadores lendo seu código. </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Modifique os dados armazenados no índice <code>0</code> de <code>myArray</code> para um valor de <code>45</code> . </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: '<code>myArray</code> agora deve ser [45,64,99].'
|
||||
testString: 'assert((function(){if(typeof myArray != "undefined" && myArray[0] == 45 && myArray[1] == 64 && myArray[2] == 99){return true;}else{return false;}})(), "<code>myArray</code> should now be [45,64,99].");'
|
||||
- text: Você deve estar usando o índice correto para modificar o valor em <code>myArray</code> .
|
||||
testString: 'assert((function(){if(code.match(/myArray\[0\]\s*=\s*/g)){return true;}else{return false;}})(), "You should be using correct index to modify the value in <code>myArray</code>.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var ourArray = [18,64,99];
|
||||
ourArray[1] = 45; // ourArray now equals [18,45,99].
|
||||
|
||||
// Setup
|
||||
var myArray = [18,64,99];
|
||||
|
||||
// Only change code below this line.
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,80 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244df
|
||||
title: Multiple Identical Options in Switch Statements
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Múltiplas Opções Idênticas em Instruções de Comutação
|
||||
---
|
||||
|
||||
## Description
|
||||
undefined
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Escreva uma instrução switch para definir a <code>answer</code> para os seguintes intervalos: <br> <code>1-3</code> - "baixo" <br> <code>4-6</code> - "Mid" <br> <code>7-9</code> - <strong>Nota</strong> "Alta" <br> Você precisará ter uma declaração de <code>case</code> para cada número no intervalo. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>sequentialSizes(1)</code> deve retornar "Low"
|
||||
testString: 'assert(sequentialSizes(1) === "Low", "<code>sequentialSizes(1)</code> should return "Low"");'
|
||||
- text: <code>sequentialSizes(2)</code> deve retornar "Low"
|
||||
testString: 'assert(sequentialSizes(2) === "Low", "<code>sequentialSizes(2)</code> should return "Low"");'
|
||||
- text: <code>sequentialSizes(3)</code> deve retornar "Low"
|
||||
testString: 'assert(sequentialSizes(3) === "Low", "<code>sequentialSizes(3)</code> should return "Low"");'
|
||||
- text: <code>sequentialSizes(4)</code> deve retornar "Mid"
|
||||
testString: 'assert(sequentialSizes(4) === "Mid", "<code>sequentialSizes(4)</code> should return "Mid"");'
|
||||
- text: <code>sequentialSizes(5)</code> deve retornar "Mid"
|
||||
testString: 'assert(sequentialSizes(5) === "Mid", "<code>sequentialSizes(5)</code> should return "Mid"");'
|
||||
- text: <code>sequentialSizes(6)</code> deve retornar "Mid"
|
||||
testString: 'assert(sequentialSizes(6) === "Mid", "<code>sequentialSizes(6)</code> should return "Mid"");'
|
||||
- text: <code>sequentialSizes(7)</code> deve retornar "High"
|
||||
testString: 'assert(sequentialSizes(7) === "High", "<code>sequentialSizes(7)</code> should return "High"");'
|
||||
- text: <code>sequentialSizes(8)</code> deve retornar "High"
|
||||
testString: 'assert(sequentialSizes(8) === "High", "<code>sequentialSizes(8)</code> should return "High"");'
|
||||
- text: <code>sequentialSizes(9)</code> deve retornar "High"
|
||||
testString: 'assert(sequentialSizes(9) === "High", "<code>sequentialSizes(9)</code> should return "High"");'
|
||||
- text: Você não deve usar nenhuma instrução <code>if</code> ou <code>else</code>
|
||||
testString: 'assert(!/else/g.test(code) || !/if/g.test(code), "You should not use any <code>if</code> or <code>else</code> statements");'
|
||||
- text: Você deve ter nove declarações de <code>case</code>
|
||||
testString: 'assert(code.match(/case/g).length === 9, "You should have nine <code>case</code> statements");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function sequentialSizes(val) {
|
||||
var answer = "";
|
||||
// Only change code below this line
|
||||
|
||||
|
||||
|
||||
// Only change code above this line
|
||||
return answer;
|
||||
}
|
||||
|
||||
// Change this value to test
|
||||
sequentialSizes(1);
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,59 +0,0 @@
|
||||
---
|
||||
id: bd7993c9c69feddfaeb7bdef
|
||||
title: Multiply Two Decimals with JavaScript
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Multiplique dois decimais com JavaScript
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Em JavaScript, você também pode realizar cálculos com números decimais, como números inteiros. Vamos multiplicar dois decimais juntos para obter seu produto. </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Altere o valor <code>0.0</code> para que o produto seja igual a <code>5.0</code> . </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: A variável <code>product</code> deve ser igual a <code>5.0</code> .
|
||||
testString: 'assert(product === 5.0, "The variable <code>product</code> should equal <code>5.0</code>.");'
|
||||
- text: Você deve usar o operador <code>*</code>
|
||||
testString: 'assert(/\*/.test(code), "You should use the <code>*</code> operator");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
var product = 2.0 * 0.0;
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,59 +0,0 @@
|
||||
---
|
||||
id: cf1231c1c11feddfaeb5bdef
|
||||
title: Multiply Two Numbers with JavaScript
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Multiplique dois números com JavaScript
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Nós também podemos multiplicar um número por outro. JavaScript usa o símbolo <code>*</code> para multiplicação de dois números. <p> <strong>Exemplo</strong> </p><blockquote> myVar = 13 * 13; // atribuído 169 </blockquote></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Altere <code>0</code> para que o produto seja igual a <code>80</code> . </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Faça o <code>product</code> variável igual a 80
|
||||
testString: 'assert(product === 80,"Make the variable <code>product</code> equal 80");'
|
||||
- text: Use o operador <code>*</code>
|
||||
testString: 'assert(/\*/.test(code), "Use the <code>*</code> operator");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
var product = 8 * 0;
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,61 +0,0 @@
|
||||
---
|
||||
id: cf1111c1c11feddfaeb7bdef
|
||||
title: Nest one Array within Another Array
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Aninhar uma matriz dentro de outra matriz
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Você também pode aninhar matrizes dentro de outras matrizes, como este: <code>[["Bulls", 23], ["White Sox", 45]]</code> . Isso também é chamado <dfn>de matriz multidimensional <dfn>.</dfn></dfn> </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Crie uma matriz aninhada chamada <code>myArray</code> . </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>myArray</code> deve ter pelo menos um array aninhado em outro array.
|
||||
testString: 'assert(Array.isArray(myArray) && myArray.some(Array.isArray), "<code>myArray</code> should have at least one array nested within another array.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var ourArray = [["the universe", 42], ["everything", 101010]];
|
||||
|
||||
// Only change code below this line.
|
||||
var myArray = [];
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,62 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244e1
|
||||
title: Nesting For Loops
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Aninhando For Loops
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Se você tiver um array multidimensional, você pode usar a mesma lógica do waypoint anterior para percorrer tanto o array quanto qualquer sub-array. Aqui está um exemplo: <blockquote> var arr = [ <br> [1,2], [3,4], [5,6] <br> ]; <br> para (var i = 0; i <arr.length; i ++) { <br> para (var j = 0; j <arr [i]. comprimento; j ++) { <br> console.log (arr [i] [j]); <br> } <br> } </blockquote> Isto produz cada sub-elemento em <code>arr</code> um de cada vez. Note que para o loop interno, estamos verificando o <code>.length</code> de <code>arr[i]</code> , já que <code>arr[i]</code> é ele próprio um array. </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Modifique a função <code>multiplyAll</code> para que multiplique a variável do <code>product</code> por cada número nos sub-arrays do <code>arr</code> </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: '<code>multiplyAll([[1],[2],[3]])</code> deve retornar <code>6</code>'
|
||||
testString: 'assert(multiplyAll([[1],[2],[3]]) === 6, "<code>multiplyAll([[1],[2],[3]])</code> should return <code>6</code>");'
|
||||
- text: '<code>multiplyAll([[1,2],[3,4],[5,6,7]])</code> deve retornar <code>5040</code>'
|
||||
testString: 'assert(multiplyAll([[1,2],[3,4],[5,6,7]]) === 5040, "<code>multiplyAll([[1,2],[3,4],[5,6,7]])</code> should return <code>5040</code>");'
|
||||
- text: '<code>multiplyAll([[5,1],[0.2, 4, 0.5],[3, 9]])</code> deve retornar <code>54</code>'
|
||||
testString: 'assert(multiplyAll([[5,1],[0.2, 4, 0.5],[3, 9]]) === 54, "<code>multiplyAll([[5,1],[0.2, 4, 0.5],[3, 9]])</code> should return <code>54</code>");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function multiplyAll(arr) {
|
||||
var product = 1;
|
||||
// Only change code below this line
|
||||
|
||||
// Only change code above this line
|
||||
return product;
|
||||
}
|
||||
|
||||
// Modify values below to test your code
|
||||
multiplyAll([[1,2],[3,4],[5,6,7]]);
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,97 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244bd
|
||||
title: Passing Values to Functions with Arguments
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Passando Valores para Funções com Argumentos
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> <dfn>Parâmetros</dfn> são variáveis que atuam como espaços reservados para os valores que devem ser inseridos em uma função quando ela é chamada. Quando uma função é definida, ela é tipicamente definida junto com um ou mais parâmetros. Os valores reais que são inseridos (ou <dfn>"passados"</dfn> ) em uma função quando são chamados são conhecidos como <dfn>argumentos</dfn> . Aqui está uma função com dois parâmetros, <code>param1</code> e <code>param2</code> : <blockquote> function testFun (param1, param2) { <br> console.log (param1, param2); <br> } </blockquote> Então podemos chamar <code>testFun</code> : <code>testFun("Hello", "World");</code> Nós passamos dois argumentos, <code>"Hello"</code> e <code>"World"</code> . Dentro da função, <code>param1</code> será igual a "Hello" e <code>param2</code> será igual a "World". Note que você poderia chamar <code>testFun</code> novamente com diferentes argumentos e os parâmetros assumiriam o valor dos novos argumentos. </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"><ol><li> Crie uma função chamada <code>functionWithArgs</code> que aceita dois argumentos e produz sua soma no console dev. </li><li> Chame a função com dois números como argumentos. </li></ol></section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>functionWithArgs</code> deve ser uma função
|
||||
testString: 'assert(typeof functionWithArgs === "function", "<code>functionWithArgs</code> should be a function");'
|
||||
- text: '<code>functionWithArgs(1,2)</code> deve produzir <code>3</code>'
|
||||
testString: 'if(typeof functionWithArgs === "function") { capture(); functionWithArgs(1,2); uncapture(); } assert(logOutput == 3, "<code>functionWithArgs(1,2)</code> should output <code>3</code>");'
|
||||
- text: '<code>functionWithArgs(7,9)</code> deve produzir <code>16</code>'
|
||||
testString: 'if(typeof functionWithArgs === "function") { capture(); functionWithArgs(7,9); uncapture(); } assert(logOutput == 16, "<code>functionWithArgs(7,9)</code> should output <code>16</code>");'
|
||||
- text: Chame <code>functionWithArgs</code> com dois números depois de defini-lo.
|
||||
testString: 'assert(/^\s*functionWithArgs\s*\(\s*\d+\s*,\s*\d+\s*\)\s*;/m.test(code), "Call <code>functionWithArgs</code> with two numbers after you define it.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
function ourFunctionWithArgs(a, b) {
|
||||
console.log(a - b);
|
||||
}
|
||||
ourFunctionWithArgs(10, 5); // Outputs 5
|
||||
|
||||
// Only change code below this line.
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
### Before Test
|
||||
<div id='js-setup'>
|
||||
|
||||
```js
|
||||
var logOutput = "";
|
||||
var originalConsole = console
|
||||
function capture() {
|
||||
var nativeLog = console.log;
|
||||
console.log = function (message) {
|
||||
if(message) logOutput = JSON.stringify(message).trim();
|
||||
if(nativeLog.apply) {
|
||||
nativeLog.apply(originalConsole, arguments);
|
||||
} else {
|
||||
var nativeMsg = Array.prototype.slice.apply(arguments).join(' ');
|
||||
nativeLog(nativeMsg);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function uncapture() {
|
||||
console.log = originalConsole.log;
|
||||
}
|
||||
|
||||
capture();
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,62 +0,0 @@
|
||||
---
|
||||
id: 599a789b454f2bbd91a3ff4d
|
||||
title: Practice comparing different values
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Pratique a comparação de valores diferentes
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Nos dois últimos desafios, aprendemos sobre o operador de igualdade ( <code>==</code> ) e o operador de igualdade estrito ( <code>===</code> ). Vamos fazer uma revisão rápida e praticar o uso desses operadores um pouco mais. Se os valores que estão sendo comparados não forem do mesmo tipo, o operador de igualdade executará uma conversão de tipo e, em seguida, avaliará os valores. No entanto, o operador de igualdade estrita irá comparar tanto o tipo de dados quanto o valor como está, sem converter um tipo para o outro. <strong>Exemplos</strong> <blockquote> 3 == '3' // retorna verdadeiro porque o JavaScript executa conversão de tipo de string para number <br> 3 === '3' // retorna falso porque os tipos são diferentes e o tipo de conversão não é executado </blockquote> <strong>Nota</strong> <br> Em JavaScript, você pode determinar o tipo de uma variável ou um valor com o operador <code>typeof</code> , da seguinte maneira: <blockquote> typeof 3 // retorna 'number' <br> typeof '3' // retorna 'string' </blockquote></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> A função <code>compareEquality</code> no editor compara dois valores usando o <code>equality operator</code> . Modifique a função para que ela retorne "Equal" somente quando os valores forem estritamente iguais. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: '<code>compareEquality(10, "10")</code> deve retornar "Not Equal"'
|
||||
testString: 'assert(compareEquality(10, "10") === "Not Equal", "<code>compareEquality(10, "10")</code> should return "Not Equal"");'
|
||||
- text: '<code>compareEquality("20", 20)</code> deve retornar "Not Equal"'
|
||||
testString: 'assert(compareEquality("20", 20) === "Not Equal", "<code>compareEquality("20", 20)</code> should return "Not Equal"");'
|
||||
- text: Você deve usar o operador <code>===</code>
|
||||
testString: 'assert(code.match(/===/g), "You should use the <code>===</code> operator");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Setup
|
||||
function compareEquality(a, b) {
|
||||
if (a == b) { // Change this line
|
||||
return "Equal";
|
||||
}
|
||||
return "Not Equal";
|
||||
}
|
||||
|
||||
// Change this value to test
|
||||
compareEquality(10, "10");
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,96 +0,0 @@
|
||||
---
|
||||
id: 5688e62ea601b2482ff8422b
|
||||
title: Profile Lookup
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Pesquisa de perfil
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Temos uma variedade de objetos representando pessoas diferentes em nossas listas de contatos. Uma função <code>lookUpProfile</code> que leva <code>name</code> e uma propriedade ( <code>prop</code> ) como argumentos foi pré-escrita para você. A função deve verificar se <code>name</code> é o <code>firstName</code> um contato real e se a propriedade fornecida ( <code>prop</code> ) é uma propriedade desse contato. Se ambos forem verdadeiros, retorne o "valor" dessa propriedade. Se o <code>name</code> não corresponder a nenhum contato, retorne <code>"No such contact"</code> Se <code>prop</code> não corresponder a nenhuma propriedade válida de um contato que corresponda ao <code>name</code> , retorne <code>"No such property"</code> </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: '<code>"Kristian", "lastName"</code> deve retornar <code>"Vos"</code>'
|
||||
testString: 'assert(lookUpProfile("Kristian","lastName") === "Vos", "<code>"Kristian", "lastName"</code> should return <code>"Vos"</code>");'
|
||||
- text: '<code>"Sherlock", "likes"</code> deve retornar <code>["Intriguing Cases", "Violin"]</code>'
|
||||
testString: 'assert.deepEqual(lookUpProfile("Sherlock", "likes"), ["Intriguing Cases", "Violin"], "<code>"Sherlock", "likes"</code> should return <code>["Intriguing Cases", "Violin"]</code>");'
|
||||
- text: '<code>"Harry","likes"</code> deve retornar um array'
|
||||
testString: 'assert(typeof lookUpProfile("Harry", "likes") === "object", "<code>"Harry","likes"</code> should return an array");'
|
||||
- text: '<code>"Bob", "number"</code> deve retornar "Nenhum contato desse tipo"'
|
||||
testString: 'assert(lookUpProfile("Bob", "number") === "No such contact", "<code>"Bob", "number"</code> should return "No such contact"");'
|
||||
- text: '<code>"Bob", "potato"</code> deve retornar "Nenhum contato desse tipo"'
|
||||
testString: 'assert(lookUpProfile("Bob", "potato") === "No such contact", "<code>"Bob", "potato"</code> should return "No such contact"");'
|
||||
- text: '<code>"Akira", "address"</code> deve retornar "Nenhuma propriedade"'
|
||||
testString: 'assert(lookUpProfile("Akira", "address") === "No such property", "<code>"Akira", "address"</code> should return "No such property"");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```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"]
|
||||
}
|
||||
];
|
||||
|
||||
|
||||
function lookUpProfile(name, prop){
|
||||
// Only change code below this line
|
||||
|
||||
// Only change code above this line
|
||||
}
|
||||
|
||||
// Change these values to test your function
|
||||
lookUpProfile("Akira", "likes");
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,59 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244b4
|
||||
title: Quoting Strings with Single Quotes
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Citando Strings com Citações Únicas
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Valores de <dfn>string</dfn> em JavaScript podem ser escritos com aspas simples ou duplas, contanto que você comece e termine com o mesmo tipo de cotação. Ao contrário de algumas outras linguagens de programação, aspas simples e duplas funcionam da mesma forma em JavaScript. <blockquote> doubleQuoteStr = "Esta é uma string"; <br> singleQuoteStr = 'Esta também é uma string'; </blockquote> A razão pela qual você pode querer usar um tipo de citação sobre o outro é se você quer usar ambos em uma string. Isso pode acontecer se você quiser salvar uma conversa em uma string e colocar a conversa entre aspas. Outro uso para isso seria salvar uma tag <code><a></code> com vários atributos entre aspas, tudo dentro de uma string. <blockquote> conversation = 'Finn exclama a Jake, "Algébrico!"'; </blockquote> No entanto, isso se torna um problema se você precisar usar as cotas mais externas dentro dele. Lembre-se, uma string tem o mesmo tipo de citação no começo e no fim. Mas se você tiver a mesma cotação em algum lugar no meio, a string parará antes e lançará um erro. <blockquote> goodStr = 'Jake pergunta a Finn: "Ei, vamos em uma aventura?"'; <br> badStr = 'Finn responde: "Vamos!"'; // lança um erro </blockquote> No <dfn>goodStr</dfn> acima, você pode usar as <dfn>duaspas</dfn> com segurança usando a barra invertida <code>\</code> como um caractere de escape. <strong>Nota</strong> <br> A contrabarra <code>\</code> não deve ser confundida com a barra <code>/</code> . Eles não fazem a mesma coisa. </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Altere a string fornecida para uma string com aspas simples no início e no final e sem caracteres de escape. Agora, a tag <code><a></code> na string usa aspas duplas em todos os lugares. Você precisará alterar as aspas externas para aspas simples para poder remover os caracteres de escape. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Remova todas as <code>backslashes</code> ( <code>\</code> )
|
||||
testString: 'assert(!/\\/g.test(code) && myStr.match("\\s*<a href\\s*=\\s*"http://www.example.com"\\s*target\\s*=\\s*"_blank">\\s*Link\\s*</a>\\s*"), "Remove all the <code>backslashes</code> (<code>\</code>)");'
|
||||
- text: 'Você deve ter duas aspas simples <code>'</code> e quatro aspas duplas <code>"</code>'
|
||||
testString: 'assert(code.match(/"/g).length === 4 && code.match(/"/g).length === 2, "You should have two single quotes <code>'</code> and four double quotes <code>"</code>");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
var myStr = "<a href=\"http://www.example.com\" target=\"_blank\">Link</a>";
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,107 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244cf
|
||||
title: Record Collection
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Colecção de registos
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Você recebe um objeto JSON representando uma parte de sua coleção de álbuns musicais. Cada álbum tem várias propriedades e um número de identificação exclusivo como sua chave. Nem todos os álbuns possuem informações completas. Escreva uma função que tenha um <code>id</code> de álbum (como <code>2548</code> ), um <code>prop</code> propriedade (como <code>"artist"</code> ou <code>"tracks"</code> ) e um <code>value</code> (como <code>"Addicted to Love"</code> ) para modificar os dados nessa coleção. Se <code>prop</code> não for <code>"tracks"</code> e o <code>value</code> não estiver vazio ( <code>""</code> ), atualize ou defina o <code>value</code> para a propriedade desse álbum de registros. Sua função deve sempre retornar todo o objeto da coleção. Existem várias regras para lidar com dados incompletos: se <code>prop</code> é <code>"tracks"</code> mas o álbum não tem uma propriedade <code>"tracks"</code> , crie um array vazio antes de adicionar o novo valor à propriedade correspondente do álbum. Se <code>prop</code> for <code>"tracks"</code> e o <code>value</code> não estiver vazio ( <code>""</code> ), insira o <code>value</code> no final da matriz de <code>tracks</code> existente no álbum. Se o <code>value</code> estiver vazio ( <code>""</code> ), exclua a propriedade <code>prop</code> fornecida do álbum. <strong>Dicas</strong> <br> Use a <code>bracket notation</code> ao <a href="/learn/javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-variables" target="_blank">acessar as propriedades do objeto com variáveis</a> . Push é um método de matriz que você pode ler sobre o <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push" target="_blank">Mozilla Developer Network</a> . Você pode consultar a <a href="/learn/javascript-algorithms-and-data-structures/basic-javascript/manipulating-complex-objects" target="_blank">seção Manipulando Objetos Complexos</a> Introduzindo o JavaScript Object Notation (JSON) para uma atualização. </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: 'Após <code>updateRecords(5439, "artist", "ABBA")</code> , o <code>artist</code> deve ser <code>"ABBA"</code>'
|
||||
testString: 'collection = collectionCopy; assert(updateRecords(5439, "artist", "ABBA")[5439]["artist"] === "ABBA", "After <code>updateRecords(5439, "artist", "ABBA")</code>, <code>artist</code> should be <code>"ABBA"</code>");'
|
||||
- text: 'Depois de <code>updateRecords(5439, "tracks", "Take a Chance on Me")</code> , as <code>tracks</code> devem ter <code>"Take a Chance on Me"</code> como o último elemento.'
|
||||
testString: 'assert(updateRecords(5439, "tracks", "Take a Chance on Me")[5439]["tracks"].pop() === "Take a Chance on Me", "After <code>updateRecords(5439, "tracks", "Take a Chance on Me")</code>, <code>tracks</code> should have <code>"Take a Chance on Me"</code> as the last element.");'
|
||||
- text: 'Após <code>updateRecords(2548, "artist", "")</code> , o <code>artist</code> não deve ser definido'
|
||||
testString: 'updateRecords(2548, "artist", ""); assert(!collection[2548].hasOwnProperty("artist"), "After <code>updateRecords(2548, "artist", "")</code>, <code>artist</code> should not be set");'
|
||||
- text: 'Depois de <code>updateRecords(1245, "tracks", "Addicted to Love")</code> , as <code>tracks</code> devem ter <code>"Addicted to Love"</code> como o último elemento.'
|
||||
testString: 'assert(updateRecords(1245, "tracks", "Addicted to Love")[1245]["tracks"].pop() === "Addicted to Love", "After <code>updateRecords(1245, "tracks", "Addicted to Love")</code>, <code>tracks</code> should have <code>"Addicted to Love"</code> as the last element.");'
|
||||
- text: 'Depois de <code>updateRecords(2468, "tracks", "Free")</code> , as <code>tracks</code> devem ter <code>"1999"</code> como o primeiro elemento.'
|
||||
testString: 'assert(updateRecords(2468, "tracks", "Free")[2468]["tracks"][0] === "1999", "After <code>updateRecords(2468, "tracks", "Free")</code>, <code>tracks</code> should have <code>"1999"</code> as the first element.");'
|
||||
- text: 'Após <code>updateRecords(2548, "tracks", "")</code> , as <code>tracks</code> não devem ser definidas'
|
||||
testString: 'updateRecords(2548, "tracks", ""); assert(!collection[2548].hasOwnProperty("tracks"), "After <code>updateRecords(2548, "tracks", "")</code>, <code>tracks</code> should not be set");'
|
||||
- text: 'Após <code>updateRecords(1245, "album", "Riptide")</code> , o <code>album</code> deve ser <code>"Riptide"</code>'
|
||||
testString: 'assert(updateRecords(1245, "album", "Riptide")[1245]["album"] === "Riptide", "After <code>updateRecords(1245, "album", "Riptide")</code>, <code>album</code> should be <code>"Riptide"</code>");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var collection = {
|
||||
"2548": {
|
||||
"album": "Slippery When Wet",
|
||||
"artist": "Bon Jovi",
|
||||
"tracks": [
|
||||
"Let It Rock",
|
||||
"You Give Love a Bad Name"
|
||||
]
|
||||
},
|
||||
"2468": {
|
||||
"album": "1999",
|
||||
"artist": "Prince",
|
||||
"tracks": [
|
||||
"1999",
|
||||
"Little Red Corvette"
|
||||
]
|
||||
},
|
||||
"1245": {
|
||||
"artist": "Robert Palmer",
|
||||
"tracks": [ ]
|
||||
},
|
||||
"5439": {
|
||||
"album": "ABBA Gold"
|
||||
}
|
||||
};
|
||||
// Keep a copy of the collection for tests
|
||||
var collectionCopy = JSON.parse(JSON.stringify(collection));
|
||||
|
||||
// Only change code below this line
|
||||
function updateRecords(id, prop, value) {
|
||||
|
||||
|
||||
return collection;
|
||||
}
|
||||
|
||||
// Alter values below to test your code
|
||||
updateRecords(5439, "artist", "ABBA");
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,88 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244e0
|
||||
title: Replacing If Else Chains with Switch
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Substituindo se outras cadeias com o interruptor
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Se você tiver muitas opções para escolher, uma instrução <code>switch</code> pode ser mais fácil de gravar do que muitas instruções encadeadas <code>if</code> / <code>else if</code> . Os seguintes: <blockquote> if (val === 1) { <br> answer = "a"; <br> } else if (val === 2) { <br> answer = "b"; <br> } outro { <br> answer = "c"; <br> } </blockquote> pode ser substituído por: <blockquote> interruptor (val) { <br> caso 1: <br> answer = "a"; <br> pausa; <br> caso 2: <br> answer = "b"; <br> pausa; <br> padrão: <br> answer = "c"; <br> } </blockquote></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Altere as instruções encadeadas <code>if</code> / <code>else if</code> para uma instrução <code>switch</code> . </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Você não deve usar nenhuma <code>else</code> instrução em nenhum lugar do editor
|
||||
testString: 'assert(!/else/g.test(code), "You should not use any <code>else</code> statements anywhere in the editor");'
|
||||
- text: Você não deve usar nenhuma instrução <code>if</code> nenhum lugar do editor
|
||||
testString: 'assert(!/if/g.test(code), "You should not use any <code>if</code> statements anywhere in the editor");'
|
||||
- text: Você deve ter pelo menos quatro declarações de <code>break</code>
|
||||
testString: 'assert(code.match(/break/g).length >= 4, "You should have at least four <code>break</code> statements");'
|
||||
- text: <code>chainToSwitch("bob")</code> deve ser "Marley"
|
||||
testString: 'assert(chainToSwitch("bob") === "Marley", "<code>chainToSwitch("bob")</code> should be "Marley"");'
|
||||
- text: <code>chainToSwitch(42)</code> deve ser "A resposta"
|
||||
testString: 'assert(chainToSwitch(42) === "The Answer", "<code>chainToSwitch(42)</code> should be "The Answer"");'
|
||||
- text: '<code>chainToSwitch(1)</code> deve ser "Não existe # 1"'
|
||||
testString: 'assert(chainToSwitch(1) === "There is no #1", "<code>chainToSwitch(1)</code> should be "There is no #1"");'
|
||||
- text: <code>chainToSwitch(99)</code> deve ser <code>chainToSwitch(99)</code> !
|
||||
testString: 'assert(chainToSwitch(99) === "Missed me by this much!", "<code>chainToSwitch(99)</code> should be "Missed me by this much!"");'
|
||||
- text: <code>chainToSwitch(7)</code> deve ser "Ate Nine"
|
||||
testString: 'assert(chainToSwitch(7) === "Ate Nine", "<code>chainToSwitch(7)</code> should be "Ate Nine"");'
|
||||
- text: <code>chainToSwitch("John")</code> deve ser "" (string vazia)
|
||||
testString: 'assert(chainToSwitch("John") === "", "<code>chainToSwitch("John")</code> should be "" (empty string)");'
|
||||
- text: <code>chainToSwitch(156)</code> deve ser "" (string vazia)
|
||||
testString: 'assert(chainToSwitch(156) === "", "<code>chainToSwitch(156)</code> should be "" (empty string)");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function chainToSwitch(val) {
|
||||
var answer = "";
|
||||
// Only change code below this line
|
||||
|
||||
if (val === "bob") {
|
||||
answer = "Marley";
|
||||
} else if (val === 42) {
|
||||
answer = "The Answer";
|
||||
} else if (val === 1) {
|
||||
answer = "There is no #1";
|
||||
} else if (val === 99) {
|
||||
answer = "Missed me by this much!";
|
||||
} else if (val === 7) {
|
||||
answer = "Ate Nine";
|
||||
}
|
||||
|
||||
// Only change code above this line
|
||||
return answer;
|
||||
}
|
||||
|
||||
// Change this value to test
|
||||
chainToSwitch(7);
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,64 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244c2
|
||||
title: Return a Value from a Function with Return
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Retornar um valor de uma função com retorno
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Podemos passar valores para uma função com <dfn>argumentos</dfn> . Você pode usar uma instrução de <code>return</code> para enviar um valor de volta de uma função. <strong>Exemplo</strong> <blockquote> function plusThree (num) { <br> return num + 3; <br> } <br> var resposta = mais três (5); // 8 </blockquote> <code>plusThree</code> aceita um <dfn>argumento</dfn> para <code>num</code> e retorna um valor igual a <code>num + 3</code> . </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Crie uma função <code>timesFive</code> que aceite um argumento, multiplique por <code>5</code> e retorne o novo valor. Veja a última linha no editor para um exemplo de como você pode testar sua função <code>timesFive</code> . </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>timesFive</code> deve ser uma função
|
||||
testString: 'assert(typeof timesFive === "function", "<code>timesFive</code> should be a function");'
|
||||
- text: <code>timesFive(5)</code> deve retornar <code>25</code>
|
||||
testString: 'assert(timesFive(5) === 25, "<code>timesFive(5)</code> should return <code>25</code>");'
|
||||
- text: <code>timesFive(2)</code> deve retornar <code>10</code>
|
||||
testString: 'assert(timesFive(2) === 10, "<code>timesFive(2)</code> should return <code>10</code>");'
|
||||
- text: <code>timesFive(0)</code> deve retornar <code>0</code>
|
||||
testString: 'assert(timesFive(0) === 0, "<code>timesFive(0)</code> should return <code>0</code>");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
function minusSeven(num) {
|
||||
return num - 7;
|
||||
}
|
||||
|
||||
// Only change code below this line
|
||||
|
||||
|
||||
|
||||
console.log(minusSeven(10));
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,71 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244c4
|
||||
title: Return Early Pattern for Functions
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Retorna o padrão inicial para funções
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Quando uma instrução de <code>return</code> é atingida, a execução da função atual é interrompida e o controle retorna ao local de chamada. <strong>Exemplo</strong> <blockquote> function myFun () { <br> console.log ("Olá"); <br> return "mundo"; <br> console.log ("byebye") <br> } <br> myFun (); </blockquote> O acima saídas "Olá" para o console, retorna "World", mas <code>"byebye"</code> nunca é saída, porque a função sai na declaração de <code>return</code> . </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Modifique a função <code>abTest</code> modo que, se <code>a</code> ou <code>b</code> forem menores que <code>0</code> a função sairá imediatamente com um valor <code>undefined</code> . <strong>Sugestão</strong> <br> Lembre-se de que <a href="http://www.freecodecamp.org/challenges/understanding-uninitialized-variables" target="_blank"><code>undefined</code> é uma palavra-chave</a> , não uma string. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: '<code>abTest(2,2)</code> deve retornar um número'
|
||||
testString: 'assert(typeof abTest(2,2) === "number" , "<code>abTest(2,2)</code> should return a number");'
|
||||
- text: '<code>abTest(2,2)</code> deve retornar <code>8</code>'
|
||||
testString: 'assert(abTest(2,2) === 8 , "<code>abTest(2,2)</code> should return <code>8</code>");'
|
||||
- text: '<code>abTest(-2,2)</code> deve retornar <code>undefined</code>'
|
||||
testString: 'assert(abTest(-2,2) === undefined , "<code>abTest(-2,2)</code> should return <code>undefined</code>");'
|
||||
- text: '<code>abTest(2,-2)</code> deve retornar <code>undefined</code>'
|
||||
testString: 'assert(abTest(2,-2) === undefined , "<code>abTest(2,-2)</code> should return <code>undefined</code>");'
|
||||
- text: '<code>abTest(2,8)</code> deve retornar <code>18</code>'
|
||||
testString: 'assert(abTest(2,8) === 18 , "<code>abTest(2,8)</code> should return <code>18</code>");'
|
||||
- text: '<code>abTest(3,3)</code> deve retornar <code>12</code>'
|
||||
testString: 'assert(abTest(3,3) === 12 , "<code>abTest(3,3)</code> should return <code>12</code>");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Setup
|
||||
function abTest(a, b) {
|
||||
// Only change code below this line
|
||||
|
||||
|
||||
|
||||
// Only change code above this line
|
||||
|
||||
return Math.round(Math.pow(Math.sqrt(a) + Math.sqrt(b), 2));
|
||||
}
|
||||
|
||||
// Change values below to test your code
|
||||
abTest(2,2);
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,63 +0,0 @@
|
||||
---
|
||||
id: 5679ceb97cbaa8c51670a16b
|
||||
title: Returning Boolean Values from Functions
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Retornando valores booleanos de funções
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Você pode se lembrar de <a href="/learn/javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-equality-operator" target="_blank">Comparação com o Operador de Igualdade</a> que todos os operadores de comparação retornam um valor booleano <code>true</code> ou <code>false</code> . Às vezes as pessoas usam uma instrução if / else para fazer uma comparação, como esta: <blockquote> função isEqual (a, b) { <br> if (a === b) { <br> retorno verdadeiro; <br> } outro { <br> retorna falso; <br> } <br> } </blockquote> Mas há uma maneira melhor de fazer isso. Como <code>===</code> retorna <code>true</code> ou <code>false</code> , podemos retornar o resultado da comparação: <blockquote> função isEqual (a, b) { <br> return a === b; <br> } </blockquote></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Corrigir a função <code>isLess</code> para remover as instruções <code>if/else</code> . </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: '<code>isLess(10,15)</code> deve retornar <code>true</code>'
|
||||
testString: 'assert(isLess(10,15) === true, "<code>isLess(10,15)</code> should return <code>true</code>");'
|
||||
- text: '<code>isLess(15,10)</code> deve retornar <code>false</code>'
|
||||
testString: 'assert(isLess(15, 10) === false, "<code>isLess(15,10)</code> should return <code>false</code>");'
|
||||
- text: Você não deve usar nenhuma instrução <code>if</code> ou <code>else</code>
|
||||
testString: 'assert(!/if|else/g.test(code), "You should not use any <code>if</code> or <code>else</code> statements");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function isLess(a, b) {
|
||||
// Fix this code
|
||||
if (a < b) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Change these values to test
|
||||
isLess(10, 15);
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,70 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244dd
|
||||
title: Selecting from Many Options with Switch Statements
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Selecionando a partir de muitas opções com instruções de troca
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Se você tiver muitas opções para escolher, use uma instrução <code>switch</code> . Uma instrução <code>switch</code> testa um valor e pode ter várias instruções <code>case</code> que definem vários valores possíveis. As declarações são executadas a partir do primeiro valor do <code>case</code> correspondente até que uma <code>break</code> seja encontrada. Aqui está um exemplo de <dfn>pseudocódigo</dfn> : <blockquote> switch (num) { <br> valor do caso1: <br> statement1; <br> pausa; <br> valor do caso2: <br> statement2; <br> pausa; <br> ... <br> case valueN: <br> statementN; <br> pausa; <br> } </blockquote> valores de <code>case</code> são testados com igualdade estrita ( <code>===</code> ). A <code>break</code> diz ao JavaScript para parar de executar instruções. Se a <code>break</code> for omitida, a próxima instrução será executada. </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Escreva uma instrução switch que teste <code>val</code> e configure a <code>answer</code> para as seguintes condições: <br> <code>1</code> - "alfa" <br> <code>2</code> - "beta" <br> <code>3</code> - "gama" <br> <code>4</code> - "delta" </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>caseInSwitch(1)</code> deve ter um valor de "alfa"
|
||||
testString: 'assert(caseInSwitch(1) === "alpha", "<code>caseInSwitch(1)</code> should have a value of "alpha"");'
|
||||
- text: <code>caseInSwitch(2)</code> deve ter um valor de "beta"
|
||||
testString: 'assert(caseInSwitch(2) === "beta", "<code>caseInSwitch(2)</code> should have a value of "beta"");'
|
||||
- text: <code>caseInSwitch(3)</code> deve ter um valor de "gamma"
|
||||
testString: 'assert(caseInSwitch(3) === "gamma", "<code>caseInSwitch(3)</code> should have a value of "gamma"");'
|
||||
- text: <code>caseInSwitch(4)</code> deve ter um valor de "delta"
|
||||
testString: 'assert(caseInSwitch(4) === "delta", "<code>caseInSwitch(4)</code> should have a value of "delta"");'
|
||||
- text: Você não deve usar nenhuma instrução <code>if</code> ou <code>else</code>
|
||||
testString: 'assert(!/else/g.test(code) || !/if/g.test(code), "You should not use any <code>if</code> or <code>else</code> statements");'
|
||||
- text: Você deve ter pelo menos 3 declarações de <code>break</code>
|
||||
testString: 'assert(code.match(/break/g).length > 2, "You should have at least 3 <code>break</code> statements");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function caseInSwitch(val) {
|
||||
var answer = "";
|
||||
// Only change code below this line
|
||||
|
||||
|
||||
|
||||
// Only change code above this line
|
||||
return answer;
|
||||
}
|
||||
|
||||
// Change this value to test
|
||||
caseInSwitch(1);
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,64 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244bc
|
||||
title: Shopping List
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Lista de compras
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Crie uma lista de compras na variável <code>myList</code> . A lista deve ser um array multidimensional contendo vários sub-arrays. O primeiro elemento em cada sub-array deve conter uma string com o nome do item. O segundo elemento deve ser um número representando a quantidade, ou seja, <code>["Chocolate Bar", 15]</code> Deve haver pelo menos 5 sub-arrays na lista. </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>myList</code> deve ser um array
|
||||
testString: 'assert(isArray, "<code>myList</code> should be an array");'
|
||||
- text: Os primeiros elementos em cada um dos seus sub-arrays devem ser todos strings
|
||||
testString: 'assert(hasString, "The first elements in each of your sub-arrays must all be strings");'
|
||||
- text: Os segundos elementos em cada um dos seus sub-arrays devem ser todos números
|
||||
testString: 'assert(hasNumber, "The second elements in each of your sub-arrays must all be numbers");'
|
||||
- text: Você deve ter pelo menos 5 itens em sua lista
|
||||
testString: 'assert(count > 4, "You must have at least 5 items in your list");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
var myList = [];
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,106 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244c6
|
||||
title: Stand in Line
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Ficar na fila
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Na Ciência da Computação, uma <dfn>fila</dfn> é uma <dfn>Estrutura de Dados</dfn> abstrata, na qual os itens são mantidos em ordem. Novos itens podem ser adicionados na parte de trás da <code>queue</code> e itens antigos são retirados da frente da <code>queue</code> . Escreva uma função <code>nextInLine</code> que recebe um array ( <code>arr</code> ) e um número ( <code>item</code> ) como argumentos. Adicione o número ao final da matriz e remova o primeiro elemento da matriz. A função <code>nextInLine</code> deve então retornar o elemento que foi removido. </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions">
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: '<code>nextInLine([], 5)</code> deve retornar um número.'
|
||||
testString: 'assert.isNumber(nextInLine([],5), "<code>nextInLine([], 5)</code> should return a number.");'
|
||||
- text: '<code>nextInLine([], 1)</code> deve retornar <code>1</code>'
|
||||
testString: 'assert(nextInLine([],1) === 1, "<code>nextInLine([], 1)</code> should return <code>1</code>");'
|
||||
- text: '<code>nextInLine([2], 1)</code> deve retornar <code>2</code>'
|
||||
testString: 'assert(nextInLine([2],1) === 2, "<code>nextInLine([2], 1)</code> should return <code>2</code>");'
|
||||
- text: '<code>nextInLine([5,6,7,8,9], 1)</code> deve retornar <code>5</code>'
|
||||
testString: 'assert(nextInLine([5,6,7,8,9],1) === 5, "<code>nextInLine([5,6,7,8,9], 1)</code> should return <code>5</code>");'
|
||||
- text: 'Após <code>nextInLine(testArr, 10)</code> , <code>testArr[4]</code> deve ser <code>10</code>'
|
||||
testString: 'nextInLine(testArr, 10); assert(testArr[4] === 10, "After <code>nextInLine(testArr, 10)</code>, <code>testArr[4]</code> should be <code>10</code>");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function nextInLine(arr, item) {
|
||||
// Your code here
|
||||
|
||||
return item; // Change this line
|
||||
}
|
||||
|
||||
// Test Setup
|
||||
var testArr = [1,2,3,4,5];
|
||||
|
||||
// Display Code
|
||||
console.log("Before: " + JSON.stringify(testArr));
|
||||
console.log(nextInLine(testArr, 6)); // Modify this line to test
|
||||
console.log("After: " + JSON.stringify(testArr));
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
### Before Test
|
||||
<div id='js-setup'>
|
||||
|
||||
```js
|
||||
var logOutput = [];
|
||||
var originalConsole = console
|
||||
function capture() {
|
||||
var nativeLog = console.log;
|
||||
console.log = function (message) {
|
||||
logOutput.push(message);
|
||||
if(nativeLog.apply) {
|
||||
nativeLog.apply(originalConsole, arguments);
|
||||
} else {
|
||||
var nativeMsg = Array.prototype.slice.apply(arguments).join(' ');
|
||||
nativeLog(nativeMsg);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function uncapture() {
|
||||
console.log = originalConsole.log;
|
||||
}
|
||||
|
||||
capture();
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,65 +0,0 @@
|
||||
---
|
||||
id: bd7993c9c69feddfaeb8bdef
|
||||
title: Store Multiple Values in one Variable using JavaScript Arrays
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Armazenar vários valores em uma variável usando matrizes JavaScript
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Com variáveis de <code>array</code> JavaScript, podemos armazenar vários dados em um só lugar. Você inicia uma declaração de matriz com um colchete de abertura, termina com um colchete de fechamento e coloca uma vírgula entre cada entrada, assim: <code>var sandwich = ["peanut butter", "jelly", "bread"]</code> . </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Modifique o novo array <code>myArray</code> para que contenha uma <code>string</code> e um <code>number</code> (nessa ordem). <strong>Sugestão</strong> <br> Consulte o código de exemplo no editor de texto, se você ficar preso. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>myArray</code> deve ser um <code>array</code> .
|
||||
testString: 'assert(typeof myArray == "object", "<code>myArray</code> should be an <code>array</code>.");'
|
||||
- text: O primeiro item no <code>myArray</code> deve ser uma <code>string</code> .
|
||||
testString: 'assert(typeof myArray[0] !== "undefined" && typeof myArray[0] == "string", "The first item in <code>myArray</code> should be a <code>string</code>.");'
|
||||
- text: O segundo item no <code>myArray</code> deve ser um <code>number</code> .
|
||||
testString: 'assert(typeof myArray[1] !== "undefined" && typeof myArray[1] == "number", "The second item in <code>myArray</code> should be a <code>number</code>.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var ourArray = ["John", 23];
|
||||
|
||||
// Only change code below this line.
|
||||
var myArray = [];
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,81 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244a8
|
||||
title: Storing Values with the Assignment Operator
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Armazenando Valores com o Operador de Atribuição
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Em JavaScript, você pode armazenar um valor em uma variável com o operador de <dfn>atribuição</dfn> . <code>myVariable = 5;</code> Isso atribui o valor <code>Number</code> <code>5</code> a <code>myVariable</code> . A atribuição sempre vai da direita para a esquerda. Tudo à direita do operador <code>=</code> é resolvido antes que o valor seja atribuído à variável à esquerda do operador. <blockquote> myVar = 5; <br> myNum = myVar; </blockquote> Isso atribui <code>5</code> para <code>myVar</code> e, em seguida, resolve <code>myVar</code> para <code>5</code> novamente e atribui a <code>myNum</code> . </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Atribua o valor <code>7</code> à variável <code>a</code> . Atribuir o conteúdo de <code>a</code> para variável <code>b</code> . </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Não mude o código acima da linha
|
||||
testString: 'assert(/var a;/.test(code) && /var b = 2;/.test(code), "Do not change code above the line");'
|
||||
- text: <code>a</code> deve ter um valor de 7
|
||||
testString: 'assert(typeof a === "number" && a === 7, "<code>a</code> should have a value of 7");'
|
||||
- text: <code>b</code> deve ter um valor de 7
|
||||
testString: 'assert(typeof b === "number" && b === 7, "<code>b</code> should have a value of 7");'
|
||||
- text: <code>a</code> deve ser atribuído a <code>b</code> com <code>=</code>
|
||||
testString: 'assert(/b\s*=\s*a\s*;/g.test(code), "<code>a</code> should be assigned to <code>b</code> with <code>=</code>");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var a;
|
||||
var b = 2;
|
||||
|
||||
// Only change code below this line
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
### Before Test
|
||||
<div id='js-setup'>
|
||||
|
||||
```js
|
||||
if (typeof a != 'undefined') {
|
||||
a = undefined;
|
||||
}
|
||||
if (typeof b != 'undefined') {
|
||||
b = undefined;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,59 +0,0 @@
|
||||
---
|
||||
id: cf1111c1c11feddfaeb4bdef
|
||||
title: Subtract One Number from Another with JavaScript
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Subtrair um número de outro com JavaScript
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Nós também podemos subtrair um número de outro. JavaScript usa o símbolo <code>-</code> para subtração. <p> <strong>Exemplo</strong> </p><blockquote> myVar = 12 - 6; // atribuído 6 </blockquote></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Altere <code>0</code> para que a diferença seja <code>12</code> . </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Faça a <code>difference</code> variável igual a 12.
|
||||
testString: 'assert(difference === 12, "Make the variable <code>difference</code> equal 12.");'
|
||||
- text: Apenas subtraia um número de 45.
|
||||
testString: 'assert(/var\s*difference\s*=\s*45\s*-\s*[0-9]*;(?!\s*[a-zA-Z0-9]+)/.test(code),"Only subtract one number from 45.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
var difference = 45 - 0;
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,67 +0,0 @@
|
||||
---
|
||||
id: 567af2437cbaa8c51670a16c
|
||||
title: Testing Objects for Properties
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Testando Objetos para Propriedades
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Às vezes é útil verificar se a propriedade de um determinado objeto existe ou não. Podemos usar o método de objetos <code>.hasOwnProperty(propname)</code> para determinar se esse objeto possui o nome da propriedade. <code>.hasOwnProperty()</code> retorna <code>true</code> ou <code>false</code> se a propriedade for encontrada ou não. <strong>Exemplo</strong> <blockquote> var myObj = { <br> cartola", <br> fundo: "calça" <br> }; <br> myObj.hasOwnProperty ("top"); // verdade <br> myObj.hasOwnProperty ("middle"); // false </blockquote></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Modifique a função <code>checkObj</code> para testar <code>myObj</code> for <code>checkProp</code> . Se a propriedade for encontrada, retorne o valor dessa propriedade. Caso contrário, retorne <code>"Not Found"</code> . </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>checkObj("gift")</code> deve retornar <code>"pony"</code> .
|
||||
testString: 'assert(checkObj("gift") === "pony", "<code>checkObj("gift")</code> should return <code>"pony"</code>.");'
|
||||
- text: <code>checkObj("pet")</code> deve retornar <code>"kitten"</code> .
|
||||
testString: 'assert(checkObj("pet") === "kitten", "<code>checkObj("pet")</code> should return <code>"kitten"</code>.");'
|
||||
- text: <code>checkObj("house")</code> deve retornar <code>"Not Found"</code> .
|
||||
testString: 'assert(checkObj("house") === "Not Found", "<code>checkObj("house")</code> should return <code>"Not Found"</code>.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var myObj = {
|
||||
gift: "pony",
|
||||
pet: "kitten",
|
||||
bed: "sleigh"
|
||||
};
|
||||
|
||||
function checkObj(checkProp) {
|
||||
// Your Code Here
|
||||
|
||||
return "Change Me!";
|
||||
}
|
||||
|
||||
// Test your code by modifying these values
|
||||
checkObj("gift");
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,64 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244ba
|
||||
title: Understand String Immutability
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Entenda a imutabilidade da corda
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Em JavaScript, os valores <code>String</code> são <dfn>imutáveis</dfn> , o que significa que eles não podem ser alterados depois de criados. Por exemplo, o código a seguir: <blockquote> var myStr = "Bob"; <br> myStr [0] = "J"; </blockquote> não pode alterar o valor de <code>myStr</code> para "Job", porque o conteúdo de <code>myStr</code> não pode ser alterado. Observe que isso <em>não</em> significa que <code>myStr</code> não possa ser alterado, apenas que os caracteres individuais de uma <dfn>string literal</dfn> não podem ser alterados. A única maneira de alterar <code>myStr</code> seria atribuí-lo com uma nova string, assim: <blockquote> var myStr = "Bob"; <br> myStr = "Job"; </blockquote></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Corrija a atribuição para <code>myStr</code> para que ela contenha o valor de string de <code>Hello World</code> usando a abordagem mostrada no exemplo acima. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>myStr</code> deve ter um valor de <code>Hello World</code>
|
||||
testString: 'assert(myStr === "Hello World", "<code>myStr</code> should have a value of <code>Hello World</code>");'
|
||||
- text: Não mude o código acima da linha
|
||||
testString: 'assert(/myStr = "Jello World"/.test(code), "Do not change the code above the line");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Setup
|
||||
var myStr = "Jello World";
|
||||
|
||||
// Only change code below this line
|
||||
|
||||
myStr[0] = "H"; // Fix Me
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,66 +0,0 @@
|
||||
---
|
||||
id: bd7123c9c441eddfaeb5bdef
|
||||
title: Understanding Boolean Values
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Compreensão dos valores booleanos
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Outro tipo de dados é o <dfn>booleano</dfn> . <code>Booleans</code> podem ser apenas um de dois valores: <code>true</code> ou <code>false</code> . Eles são basicamente pequenos comutadores on-off, em que <code>true</code> é "on" e <code>false</code> é "off". Esses dois estados são mutuamente exclusivos. <strong>Nota</strong> <br> Valores <code>Boolean</code> nunca são escritos com aspas. As <code>strings</code> <code>"true"</code> e <code>"false"</code> não são <code>Boolean</code> e não têm significado especial em JavaScript. </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Modifique a função <code>welcomeToBooleans</code> para que ela retorne <code>true</code> vez de <code>false</code> quando o botão de execução for clicado. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: A função <code>welcomeToBooleans()</code> deve retornar um valor booleano (verdadeiro / falso).
|
||||
testString: 'assert(typeof welcomeToBooleans() === "boolean", "The <code>welcomeToBooleans()</code> function should return a boolean (true/false) value.");'
|
||||
- text: <code>welcomeToBooleans()</code> deve retornar true.
|
||||
testString: 'assert(welcomeToBooleans() === true, "<code>welcomeToBooleans()</code> should return true.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function welcomeToBooleans() {
|
||||
|
||||
// Only change code below this line.
|
||||
|
||||
return false; // Change this line
|
||||
|
||||
// Only change code above this line.
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,67 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244ab
|
||||
title: Understanding Case Sensitivity in Variables
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Entendendo a sensibilidade do caso em variáveis
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Em JavaScript, todas as variáveis e nomes de função diferenciam maiúsculas de minúsculas. Isso significa que a capitalização é importante. <code>MYVAR</code> não é o mesmo que <code>MyVar</code> nem <code>myvar</code> . É possível ter várias variáveis distintas com o mesmo nome, mas diferentes invólucros. É altamente recomendável que, por motivos de clareza, você <em>não</em> use esse recurso de idioma. <h4> Melhor pratica </h4> Escreva nomes de variáveis em JavaScript no <dfn>camelCase</dfn> . No <dfn>camelCase</dfn> , os nomes de variáveis com várias palavras têm a primeira palavra em minúsculas e a primeira letra de cada palavra subsequente é maiúscula. <strong>Exemplos:</strong> <blockquote> var someVariable; <br> var anotherVariableName; <br> var thisVariableNameIsSoLong; </blockquote></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Modifique as declarações e atribuições existentes para que seus nomes usem o <dfn>camelCase</dfn> . <br> Não crie novas variáveis. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>studlyCapVar</code> é definido e tem um valor de <code>10</code>
|
||||
testString: 'assert(typeof studlyCapVar !== "undefined" && studlyCapVar === 10, "<code>studlyCapVar</code> is defined and has a value of <code>10</code>");'
|
||||
- text: <code>properCamelCase</code> é definido e tem um valor de <code>"A String"</code>
|
||||
testString: 'assert(typeof properCamelCase !== "undefined" && properCamelCase === "A String", "<code>properCamelCase</code> is defined and has a value of <code>"A String"</code>");'
|
||||
- text: <code>titleCaseOver</code> é definido e tem um valor de <code>9000</code>
|
||||
testString: 'assert(typeof titleCaseOver !== "undefined" && titleCaseOver === 9000, "<code>titleCaseOver</code> is defined and has a value of <code>9000</code>");'
|
||||
- text: <code>studlyCapVar</code> deve usar o camelCase nas seções de declaração e atribuição.
|
||||
testString: 'assert(code.match(/studlyCapVar/g).length === 2, "<code>studlyCapVar</code> should use camelCase in both declaration and assignment sections.");'
|
||||
- text: <code>properCamelCase</code> deve usar o camelCase nas seções de declaração e atribuição.
|
||||
testString: 'assert(code.match(/properCamelCase/g).length === 2, "<code>properCamelCase</code> should use camelCase in both declaration and assignment sections.");'
|
||||
- text: <code>titleCaseOver</code> deve usar o camelCase nas seções de declaração e atribuição.
|
||||
testString: 'assert(code.match(/titleCaseOver/g).length === 2, "<code>titleCaseOver</code> should use camelCase in both declaration and assignment sections.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Declarations
|
||||
var StUdLyCapVaR;
|
||||
var properCamelCase;
|
||||
var TitleCaseOver;
|
||||
|
||||
// Assignments
|
||||
STUDLYCAPVAR = 10;
|
||||
PRoperCAmelCAse = "A String";
|
||||
tITLEcASEoVER = 9000;
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,74 +0,0 @@
|
||||
---
|
||||
id: 598e8944f009e646fc236146
|
||||
title: Understanding Undefined Value returned from a Function
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Entendendo o valor indefinido retornado de uma função
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Uma função pode incluir a declaração de <code>return</code> , mas não precisa. No caso de a função não ter uma instrução de <code>return</code> , quando você a chama, a função processa o código interno, mas o valor retornado é <code>undefined</code> . <strong>Exemplo</strong> <blockquote> var sum = 0; <br> function addSum (num) { <br> soma = soma + num; <br> } <br> var returnedValue = addSum (3); // sum será modificado, mas o valor retornado é indefinido </blockquote> <code>addSum</code> é uma função sem uma declaração de <code>return</code> . A função irá alterar a variável global <code>sum</code> mas o valor retornado da função é <code>undefined</code> </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Crie uma função <code>addFive</code> sem nenhum argumento. Essa função adiciona 5 à variável <code>sum</code> , mas seu valor retornado é <code>undefined</code> . </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>addFive</code> deve ser uma função
|
||||
testString: 'assert(typeof addFive === "function", "<code>addFive</code> should be a function");'
|
||||
- text: <code>sum</code> deve ser igual a 8
|
||||
testString: 'assert(sum === 8, "<code>sum</code> should be equal to 8");'
|
||||
- text: Valor retornado de <code>addFive</code> deve ser <code>undefined</code>
|
||||
testString: 'assert(addFive() === undefined, "Returned value from <code>addFive</code> should be <code>undefined</code>");'
|
||||
- text: 'Dentro de suas funções, adicione 5 à variável <code>sum</code>'
|
||||
testString: 'assert(code.match(/(sum\s*\=\s*sum\s*\+\s*5)|(sum\s*\+\=\s*5)/g).length === 1, "Inside of your functions, add 5 to the <code>sum</code> variable");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var sum = 0;
|
||||
function addThree() {
|
||||
sum = sum + 3;
|
||||
}
|
||||
|
||||
// Only change code below this line
|
||||
|
||||
|
||||
|
||||
// Only change code above this line
|
||||
var returnedValue = addFive();
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,72 +0,0 @@
|
||||
---
|
||||
id: 56533eb9ac21ba0edf2244aa
|
||||
title: Understanding Uninitialized Variables
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Noções básicas sobre variáveis não inicializadas
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Quando variáveis JavaScript são declaradas, elas possuem um valor inicial de <code>undefined</code> . Se você fizer uma operação matemática em uma variável <code>undefined</code> , seu resultado será <code>NaN</code> que significa <dfn>"Não é um número"</dfn> . Se você concatenar uma string com uma variável <code>undefined</code> , você receberá uma <dfn>string</dfn> literal de <code>"undefined"</code> . </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Inicialize as três variáveis <code>a</code> , <code>b</code> e <code>c</code> com <code>5</code> , <code>10</code> e <code>"I am a"</code> respectivamente, para que elas não sejam <code>undefined</code> . </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>a</code> deve ser definido e avaliado para ter o valor de <code>6</code>
|
||||
testString: 'assert(typeof a === "number" && a === 6, "<code>a</code> should be defined and evaluated to have the value of <code>6</code>");'
|
||||
- text: <code>b</code> deve ser definido e avaliado para ter o valor de <code>15</code>
|
||||
testString: 'assert(typeof b === "number" && b === 15, "<code>b</code> should be defined and evaluated to have the value of <code>15</code>");'
|
||||
- text: <code>c</code> não deve conter <code>undefined</code> e deve ter um valor de "I am a String!"
|
||||
testString: 'assert(!/undefined/.test(c) && c === "I am a String!", "<code>c</code> should not contain <code>undefined</code> and should have a value of "I am a String!"");'
|
||||
- text: Não altere o código abaixo da linha
|
||||
testString: 'assert(/a = a \+ 1;/.test(code) && /b = b \+ 5;/.test(code) && /c = c \+ " String!";/.test(code), "Do not change code below the line");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Initialize these three variables
|
||||
var a;
|
||||
var b;
|
||||
var c;
|
||||
|
||||
// Do not change code below this line
|
||||
|
||||
a = a + 1;
|
||||
b = b + 5;
|
||||
c = c + " String!";
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,77 +0,0 @@
|
||||
---
|
||||
id: 56bbb991ad1ed5201cd392d1
|
||||
title: Updating Object Properties
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Atualizando Propriedades do Objeto
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Depois de criar um objeto JavaScript, você poderá atualizar suas propriedades a qualquer momento, da mesma forma que atualizaria qualquer outra variável. Você pode usar a notação de pontos ou colchetes para atualizar. Por exemplo, vamos dar uma olhada no <code>ourDog</code> : <blockquote> var ourDog = { <br> "nome": "Camper", <br> "pernas": 4, <br> "coroa": 1, <br> "amigos": ["tudo!"] <br> }; </blockquote> Desde que ele é um cão particularmente feliz, vamos mudar seu nome para "Happy Camper". Aqui está como nós atualizamos a propriedade do nome do objeto: <code>ourDog.name = "Happy Camper";</code> or <code>ourDog["name"] = "Happy Camper";</code> Agora, quando avaliamos <code>ourDog.name</code> , em vez de obter "Camper", obteremos seu novo nome, "Happy Camper". </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Atualize a <code>myDog</code> do nome do objeto <code>myDog</code> . Vamos mudar o nome dela de "Coder" para "Happy Coder". Você pode usar a notação de pontos ou colchetes. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Atualize a <code>myDog</code> <code>"name"</code> do <code>myDog</code> para igualar "Happy Coder".
|
||||
testString: 'assert(/happy coder/gi.test(myDog.name), "Update <code>myDog</code>'s <code>"name"</code> property to equal "Happy Coder".");'
|
||||
- text: Não edite a definição <code>myDog</code>
|
||||
testString: 'assert(/"name": "Coder"/.test(code), "Do not edit the <code>myDog</code> definition");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var ourDog = {
|
||||
"name": "Camper",
|
||||
"legs": 4,
|
||||
"tails": 1,
|
||||
"friends": ["everything!"]
|
||||
};
|
||||
|
||||
ourDog.name = "Happy Camper";
|
||||
|
||||
// Setup
|
||||
var myDog = {
|
||||
"name": "Coder",
|
||||
"legs": 4,
|
||||
"tails": 1,
|
||||
"friends": ["freeCodeCamp Campers"]
|
||||
};
|
||||
|
||||
// Only change code below this line.
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,70 +0,0 @@
|
||||
---
|
||||
id: bd7123c9c549eddfaeb5bdef
|
||||
title: Use Bracket Notation to Find the First Character in a String
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Use a notação de suporte para localizar o primeiro caractere em uma seqüência de caracteres
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> <code>Bracket notation</code> é uma maneira de obter um caractere em um <code>index</code> específico em uma cadeia de caracteres. A maioria das linguagens de programação modernas, como o JavaScript, não começa a contar como um ser humano. Eles começam em 0. Isso é chamado de indexação <dfn>baseada</dfn> em <dfn>zero</dfn> . Por exemplo, o caractere no índice 0 na palavra "Charles" é "C". Então, se <code>var firstName = "Charles"</code> , você pode obter o valor da primeira letra da string usando <code>firstName[0]</code> . </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Use a <dfn>notação de colchetes</dfn> para localizar o primeiro caractere na variável <code>lastName</code> e atribuí-lo a <code>firstLetterOfLastName</code> . <strong>Sugestão</strong> <br> Tente observar a declaração da variável <code>firstLetterOfFirstName</code> se você ficar preso. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: A variável <code>firstLetterOfLastName</code> deve ter o valor de <code>L</code>
|
||||
testString: 'assert(firstLetterOfLastName === "L", "The <code>firstLetterOfLastName</code> variable should have the value of <code>L</code>.");'
|
||||
- text: Você deve usar a notação de colchetes.
|
||||
testString: 'assert(code.match(/firstLetterOfLastName\s*?=\s*?lastName\[.*?\]/), "You should use bracket notation.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var firstLetterOfFirstName = "";
|
||||
var firstName = "Ada";
|
||||
|
||||
firstLetterOfFirstName = firstName[0];
|
||||
|
||||
// Setup
|
||||
var firstLetterOfLastName = "";
|
||||
var lastName = "Lovelace";
|
||||
|
||||
// Only change code below this line
|
||||
firstLetterOfLastName = lastName;
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,67 +0,0 @@
|
||||
---
|
||||
id: bd7123c9c451eddfaeb5bdef
|
||||
title: Use Bracket Notation to Find the Last Character in a String
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Use a notação de suporte para localizar o último caractere em uma string
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Para obter a última letra de uma string, você pode subtrair uma da extensão da string. Por exemplo, se <code>var firstName = "Charles"</code> , você pode obter o valor da última letra da string usando <code>firstName[firstName.length - 1]</code> . </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Use a <dfn>notação de colchetes</dfn> para encontrar o último caractere na variável <code>lastName</code> . <strong>Sugestão</strong> <br> Tente ver a declaração da variável <code>lastLetterOfFirstName</code> se você ficar preso. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>lastLetterOfLastName</code> deve ser "e".
|
||||
testString: 'assert(lastLetterOfLastName === "e", "<code>lastLetterOfLastName</code> should be "e".");'
|
||||
- text: Você tem que usar o <code>.length</code> para obter a última letra.
|
||||
testString: 'assert(code.match(/\.length/g).length === 2, "You have to use <code>.length</code> to get the last letter.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var firstName = "Ada";
|
||||
var lastLetterOfFirstName = firstName[firstName.length - 1];
|
||||
|
||||
// Setup
|
||||
var lastName = "Lovelace";
|
||||
|
||||
// Only change code below this line.
|
||||
var lastLetterOfLastName = lastName;
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,67 +0,0 @@
|
||||
---
|
||||
id: bd7123c9c450eddfaeb5bdef
|
||||
title: Use Bracket Notation to Find the Nth Character in a String
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Use a notação de suporte para localizar o caractere Nth em uma seqüência de caracteres
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Você também pode usar a <dfn>notação de colchetes</dfn> para obter o caractere em outras posições dentro de uma string. Lembre-se de que os computadores começam a contar a <code>0</code> , portanto, o primeiro caractere é, na verdade, o caractere zeroth. </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Vamos tentar definir <code>thirdLetterOfLastName</code> para igualar a terceira letra da variável <code>lastName</code> usando a notação de colchetes. <strong>Sugestão</strong> <br> Tente observar a declaração da variável <code>secondLetterOfFirstName</code> se você ficar preso. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: A variável <code>thirdLetterOfLastName</code> deve ter o valor de <code>v</code> .
|
||||
testString: 'assert(thirdLetterOfLastName === "v", "The <code>thirdLetterOfLastName</code> variable should have the value of <code>v</code>.");'
|
||||
- text: Você deve usar a notação de colchetes.
|
||||
testString: 'assert(code.match(/thirdLetterOfLastName\s*?=\s*?lastName\[.*?\]/), "You should use bracket notation.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var firstName = "Ada";
|
||||
var secondLetterOfFirstName = firstName[1];
|
||||
|
||||
// Setup
|
||||
var lastName = "Lovelace";
|
||||
|
||||
// Only change code below this line.
|
||||
var thirdLetterOfLastName = lastName;
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,67 +0,0 @@
|
||||
---
|
||||
id: bd7123c9c452eddfaeb5bdef
|
||||
title: Use Bracket Notation to Find the Nth-to-Last Character in a String
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Use a notação de suporte para localizar o caractere N-para-último em uma seqüência de caracteres
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Você pode usar o mesmo princípio que acabamos de usar para recuperar o último caractere em uma string para recuperar o caractere de enésima a última. Por exemplo, você pode obter o valor da terceira para a última letra da string <code>var firstName = "Charles"</code> usando <code>firstName[firstName.length - 3]</code> </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Use a <dfn>notação de colchetes</dfn> para localizar o penúltimo caractere na string <code>lastName</code> . <strong>Sugestão</strong> <br> Tente observar a declaração da variável <code>thirdToLastLetterOfFirstName</code> se você ficar preso. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>secondToLastLetterOfLastName</code> deve ser "c".
|
||||
testString: 'assert(secondToLastLetterOfLastName === "c", "<code>secondToLastLetterOfLastName</code> should be "c".");'
|
||||
- text: Você tem que usar o <code>.length</code> para obter a segunda última letra.
|
||||
testString: 'assert(code.match(/\.length/g).length === 2, "You have to use <code>.length</code> to get the second last letter.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var firstName = "Ada";
|
||||
var thirdToLastLetterOfFirstName = firstName[firstName.length - 3];
|
||||
|
||||
// Setup
|
||||
var lastName = "Lovelace";
|
||||
|
||||
// Only change code below this line
|
||||
var secondToLastLetterOfLastName = lastName;
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
console.info('after the test');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -1,77 +0,0 @@
|
||||
---
|
||||
id: cf1111c1c12feddfaeb3bdef
|
||||
title: Use Conditional Logic with If Statements
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Use Lógica Condicional com Declarações If
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> <code>If</code> instruções são usadas para tomar decisões no código. A palavra-chave <code>if</code> diz ao JavaScript para executar o código nas chaves em determinadas condições, definidas entre parênteses. Essas condições são conhecidas como condições <code>Boolean</code> e podem ser <code>true</code> ou <code>false</code> . Quando a condição é avaliada como <code>true</code> , o programa executa a instrução dentro das chaves. Quando a condição booleana é avaliada como <code>false</code> , a instrução dentro das chaves não será executada. <strong>Pseudo-código</strong> <blockquote> if ( <i>condição é verdadeira</i> ) { <br> <i>instrução é executada</i> <br> } </blockquote> <strong>Exemplo</strong> <blockquote> teste de função (myCondition) { <br> if (myCondition) { <br> return "Foi verdade"; <br> } <br> return "Foi falso"; <br> } <br> teste (verdadeiro); // retorna "Foi verdade" <br> teste (falso); // retorna "foi falso" </blockquote> Quando o <code>test</code> é chamado com um valor <code>true</code> , a instrução <code>if</code> avalia <code>myCondition</code> para ver se é <code>true</code> ou não. Como é <code>true</code> , a função retorna <code>"It was true"</code> . Quando chamamos <code>test</code> com um valor <code>false</code> , <code>myCondition</code> <em>não</em> é <code>true</code> e a instrução nas chaves não é executada e a função retorna <code>"It was false"</code> is <code>"It was false"</code> . </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Crie uma declaração <code>if</code> dentro da função para retornar <code>"Yes, that was true"</code> se o parâmetro <code>wasThatTrue</code> for <code>true</code> e retornar <code>"No, that was false"</code> caso contrário. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>trueOrFalse</code> deve ser uma função
|
||||
testString: 'assert(typeof trueOrFalse === "function", "<code>trueOrFalse</code> should be a function");'
|
||||
- text: <code>trueOrFalse(true)</code> deve retornar uma string
|
||||
testString: 'assert(typeof trueOrFalse(true) === "string", "<code>trueOrFalse(true)</code> should return a string");'
|
||||
- text: <code>trueOrFalse(false)</code> deve retornar uma string
|
||||
testString: 'assert(typeof trueOrFalse(false) === "string", "<code>trueOrFalse(false)</code> should return a string");'
|
||||
- text: '<code>trueOrFalse(true)</code> deve retornar "Sim, isso era verdade"'
|
||||
testString: 'assert(trueOrFalse(true) === "Yes, that was true", "<code>trueOrFalse(true)</code> should return "Yes, that was true"");'
|
||||
- text: '<code>trueOrFalse(false)</code> deve retornar "Não, isso foi falso"'
|
||||
testString: 'assert(trueOrFalse(false) === "No, that was false", "<code>trueOrFalse(false)</code> should return "No, that was false"");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
function ourTrueOrFalse(isItTrue) {
|
||||
if (isItTrue) {
|
||||
return "Yes, it's true";
|
||||
}
|
||||
return "No, it's false";
|
||||
}
|
||||
|
||||
// Setup
|
||||
function trueOrFalse(wasThatTrue) {
|
||||
|
||||
// Only change code below this line.
|
||||
|
||||
|
||||
|
||||
// Only change code above this line.
|
||||
|
||||
}
|
||||
|
||||
// Change this value to test
|
||||
trueOrFalse(true);
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user