mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-09-24 23:01:18 +08:00
chore(i18n,learn): processed translations (#48111)
This commit is contained in:
+30
-10
@@ -87,6 +87,21 @@ assert(
|
||||
The `remove` method should remove the greatest element from the max heap while maintaining the max heap property.
|
||||
|
||||
```js
|
||||
function isHeap(arr, i, n) {
|
||||
if (i >= (n - 1) / 2) {
|
||||
return true;
|
||||
}
|
||||
if (
|
||||
arr[i] >= arr[2 * i + 1] &&
|
||||
arr[i] >= arr[2 * i + 2] &&
|
||||
isHeap(arr, 2 * i + 1, n) &&
|
||||
isHeap(arr, 2 * i + 2, n)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
assert(
|
||||
(function () {
|
||||
var test = false;
|
||||
@@ -95,16 +110,21 @@ assert(
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
test.insert(30);
|
||||
test.insert(300);
|
||||
test.insert(500);
|
||||
test.insert(10);
|
||||
let result = [];
|
||||
result.push(test.remove());
|
||||
result.push(test.remove());
|
||||
result.push(test.remove());
|
||||
result.push(test.remove());
|
||||
return result.join('') == '5003003010';
|
||||
let max = Infinity;
|
||||
const [result, vals] = [[], [2, 15, 3, 7, 12, 7, 10, 90]];
|
||||
vals.forEach((val) => test.insert(val));
|
||||
for (let i = 0; i < vals.length; i++) {
|
||||
const curHeap = test.print();
|
||||
const arr = curHeap[0] === null ? curHeap.slice(1) : curHeap;
|
||||
if (!isHeap(arr, 0, arr.length - 1)) {
|
||||
return false;
|
||||
}
|
||||
const removed = test.remove();
|
||||
if(removed > max) return false
|
||||
max = removed;
|
||||
result.push(removed);
|
||||
}
|
||||
return true
|
||||
})()
|
||||
);
|
||||
```
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ dashedName: step-13
|
||||
|
||||
# --description--
|
||||
|
||||
爲你的 `.bb1` 元素添加以下樣式屬性:`display: flex;`、`flex-direction: column;` 和 `align-items: center;`。 這將使用 “flex” 或 “flexbox” 將建築物居中。 你將在另一個項目中更詳細地瞭解它。
|
||||
Center the parts of your building by turning the `.bb1` element into a flexbox parent. Use the `flex-direction` and `align-items` properties to center the children.
|
||||
|
||||
# --hints--
|
||||
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ dashedName: step-174
|
||||
|
||||
# --description--
|
||||
|
||||
Since you subtracted health from the player, you need to check `if` the player's `health` is less than or equal to `0`. If it is, call the `lose` function.
|
||||
Since you subtracted health from the player, you need to check if the player's `health` is less than or equal to `0`. If it is, call the `lose` function.
|
||||
|
||||
# --hints--
|
||||
|
||||
|
||||
+30
-10
@@ -87,6 +87,21 @@ assert(
|
||||
The `remove` method should remove the greatest element from the max heap while maintaining the max heap property.
|
||||
|
||||
```js
|
||||
function isHeap(arr, i, n) {
|
||||
if (i >= (n - 1) / 2) {
|
||||
return true;
|
||||
}
|
||||
if (
|
||||
arr[i] >= arr[2 * i + 1] &&
|
||||
arr[i] >= arr[2 * i + 2] &&
|
||||
isHeap(arr, 2 * i + 1, n) &&
|
||||
isHeap(arr, 2 * i + 2, n)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
assert(
|
||||
(function () {
|
||||
var test = false;
|
||||
@@ -95,16 +110,21 @@ assert(
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
test.insert(30);
|
||||
test.insert(300);
|
||||
test.insert(500);
|
||||
test.insert(10);
|
||||
let result = [];
|
||||
result.push(test.remove());
|
||||
result.push(test.remove());
|
||||
result.push(test.remove());
|
||||
result.push(test.remove());
|
||||
return result.join('') == '5003003010';
|
||||
let max = Infinity;
|
||||
const [result, vals] = [[], [2, 15, 3, 7, 12, 7, 10, 90]];
|
||||
vals.forEach((val) => test.insert(val));
|
||||
for (let i = 0; i < vals.length; i++) {
|
||||
const curHeap = test.print();
|
||||
const arr = curHeap[0] === null ? curHeap.slice(1) : curHeap;
|
||||
if (!isHeap(arr, 0, arr.length - 1)) {
|
||||
return false;
|
||||
}
|
||||
const removed = test.remove();
|
||||
if(removed > max) return false
|
||||
max = removed;
|
||||
result.push(removed);
|
||||
}
|
||||
return true
|
||||
})()
|
||||
);
|
||||
```
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ dashedName: step-13
|
||||
|
||||
# --description--
|
||||
|
||||
为你的 `.bb1` 元素添加以下样式属性:`display: flex;`、`flex-direction: column;` 和 `align-items: center;`。 这将使用 “flex” 或 “flexbox” 将建筑物居中。 你将在另一个项目中更详细地了解它。
|
||||
Center the parts of your building by turning the `.bb1` element into a flexbox parent. Use the `flex-direction` and `align-items` properties to center the children.
|
||||
|
||||
# --hints--
|
||||
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ dashedName: step-174
|
||||
|
||||
# --description--
|
||||
|
||||
Since you subtracted health from the player, you need to check `if` the player's `health` is less than or equal to `0`. If it is, call the `lose` function.
|
||||
Since you subtracted health from the player, you need to check if the player's `health` is less than or equal to `0`. If it is, call the `lose` function.
|
||||
|
||||
# --hints--
|
||||
|
||||
|
||||
+30
-10
@@ -87,6 +87,21 @@ assert(
|
||||
The `remove` method should remove the greatest element from the max heap while maintaining the max heap property.
|
||||
|
||||
```js
|
||||
function isHeap(arr, i, n) {
|
||||
if (i >= (n - 1) / 2) {
|
||||
return true;
|
||||
}
|
||||
if (
|
||||
arr[i] >= arr[2 * i + 1] &&
|
||||
arr[i] >= arr[2 * i + 2] &&
|
||||
isHeap(arr, 2 * i + 1, n) &&
|
||||
isHeap(arr, 2 * i + 2, n)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
assert(
|
||||
(function () {
|
||||
var test = false;
|
||||
@@ -95,16 +110,21 @@ assert(
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
test.insert(30);
|
||||
test.insert(300);
|
||||
test.insert(500);
|
||||
test.insert(10);
|
||||
let result = [];
|
||||
result.push(test.remove());
|
||||
result.push(test.remove());
|
||||
result.push(test.remove());
|
||||
result.push(test.remove());
|
||||
return result.join('') == '5003003010';
|
||||
let max = Infinity;
|
||||
const [result, vals] = [[], [2, 15, 3, 7, 12, 7, 10, 90]];
|
||||
vals.forEach((val) => test.insert(val));
|
||||
for (let i = 0; i < vals.length; i++) {
|
||||
const curHeap = test.print();
|
||||
const arr = curHeap[0] === null ? curHeap.slice(1) : curHeap;
|
||||
if (!isHeap(arr, 0, arr.length - 1)) {
|
||||
return false;
|
||||
}
|
||||
const removed = test.remove();
|
||||
if(removed > max) return false
|
||||
max = removed;
|
||||
result.push(removed);
|
||||
}
|
||||
return true
|
||||
})()
|
||||
);
|
||||
```
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ dashedName: step-13
|
||||
|
||||
# --description--
|
||||
|
||||
Give your `.bb1` element these style properties: `display: flex;`, `flex-direction: column;`, and `align-items: center;`. This will center the parts of the building using "flex" or "flexbox". You will learn about it in more detail on another project.
|
||||
Center the parts of your building by turning the `.bb1` element into a flexbox parent. Use the `flex-direction` and `align-items` properties to center the children.
|
||||
|
||||
# --hints--
|
||||
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ dashedName: step-174
|
||||
|
||||
# --description--
|
||||
|
||||
Since you subtracted health from the player, you need to check `if` the player's `health` is less than or equal to `0`. If it is, call the `lose` function.
|
||||
Since you subtracted health from the player, you need to check if the player's `health` is less than or equal to `0`. If it is, call the `lose` function.
|
||||
|
||||
# --hints--
|
||||
|
||||
|
||||
+30
-10
@@ -87,6 +87,21 @@ assert(
|
||||
The `remove` method should remove the greatest element from the max heap while maintaining the max heap property.
|
||||
|
||||
```js
|
||||
function isHeap(arr, i, n) {
|
||||
if (i >= (n - 1) / 2) {
|
||||
return true;
|
||||
}
|
||||
if (
|
||||
arr[i] >= arr[2 * i + 1] &&
|
||||
arr[i] >= arr[2 * i + 2] &&
|
||||
isHeap(arr, 2 * i + 1, n) &&
|
||||
isHeap(arr, 2 * i + 2, n)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
assert(
|
||||
(function () {
|
||||
var test = false;
|
||||
@@ -95,16 +110,21 @@ assert(
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
test.insert(30);
|
||||
test.insert(300);
|
||||
test.insert(500);
|
||||
test.insert(10);
|
||||
let result = [];
|
||||
result.push(test.remove());
|
||||
result.push(test.remove());
|
||||
result.push(test.remove());
|
||||
result.push(test.remove());
|
||||
return result.join('') == '5003003010';
|
||||
let max = Infinity;
|
||||
const [result, vals] = [[], [2, 15, 3, 7, 12, 7, 10, 90]];
|
||||
vals.forEach((val) => test.insert(val));
|
||||
for (let i = 0; i < vals.length; i++) {
|
||||
const curHeap = test.print();
|
||||
const arr = curHeap[0] === null ? curHeap.slice(1) : curHeap;
|
||||
if (!isHeap(arr, 0, arr.length - 1)) {
|
||||
return false;
|
||||
}
|
||||
const removed = test.remove();
|
||||
if(removed > max) return false
|
||||
max = removed;
|
||||
result.push(removed);
|
||||
}
|
||||
return true
|
||||
})()
|
||||
);
|
||||
```
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ dashedName: step-13
|
||||
|
||||
# --description--
|
||||
|
||||
Give your `.bb1` element these style properties: `display: flex;`, `flex-direction: column;`, and `align-items: center;`. This will center the parts of the building using "flex" or "flexbox". You will learn about it in more detail on another project.
|
||||
Center the parts of your building by turning the `.bb1` element into a flexbox parent. Use the `flex-direction` and `align-items` properties to center the children.
|
||||
|
||||
# --hints--
|
||||
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ dashedName: step-174
|
||||
|
||||
# --description--
|
||||
|
||||
Since you subtracted health from the player, you need to check `if` the player's `health` is less than or equal to `0`. If it is, call the `lose` function.
|
||||
Since you subtracted health from the player, you need to check if the player's `health` is less than or equal to `0`. If it is, call the `lose` function.
|
||||
|
||||
# --hints--
|
||||
|
||||
|
||||
+30
-10
@@ -87,6 +87,21 @@ assert(
|
||||
Il metodo remove dovrebbe rimuovere l'elemento più grande dal max heap mantenendo la proprietà max heap.
|
||||
|
||||
```js
|
||||
function isHeap(arr, i, n) {
|
||||
if (i >= (n - 1) / 2) {
|
||||
return true;
|
||||
}
|
||||
if (
|
||||
arr[i] >= arr[2 * i + 1] &&
|
||||
arr[i] >= arr[2 * i + 2] &&
|
||||
isHeap(arr, 2 * i + 1, n) &&
|
||||
isHeap(arr, 2 * i + 2, n)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
assert(
|
||||
(function () {
|
||||
var test = false;
|
||||
@@ -95,16 +110,21 @@ assert(
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
test.insert(30);
|
||||
test.insert(300);
|
||||
test.insert(500);
|
||||
test.insert(10);
|
||||
let result = [];
|
||||
result.push(test.remove());
|
||||
result.push(test.remove());
|
||||
result.push(test.remove());
|
||||
result.push(test.remove());
|
||||
return result.join('') == '5003003010';
|
||||
let max = Infinity;
|
||||
const [result, vals] = [[], [2, 15, 3, 7, 12, 7, 10, 90]];
|
||||
vals.forEach((val) => test.insert(val));
|
||||
for (let i = 0; i < vals.length; i++) {
|
||||
const curHeap = test.print();
|
||||
const arr = curHeap[0] === null ? curHeap.slice(1) : curHeap;
|
||||
if (!isHeap(arr, 0, arr.length - 1)) {
|
||||
return false;
|
||||
}
|
||||
const removed = test.remove();
|
||||
if(removed > max) return false
|
||||
max = removed;
|
||||
result.push(removed);
|
||||
}
|
||||
return true
|
||||
})()
|
||||
);
|
||||
```
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ dashedName: step-13
|
||||
|
||||
# --description--
|
||||
|
||||
Dai all'elemento `.bb1` le proprietà `display: flex;`, `flex-direction: column;` e `align-items: center;`. Così centrerai le parti dell'edificio utilizzando "flex" o "flexbox". Ne imparerai di più in un altro progetto.
|
||||
Center the parts of your building by turning the `.bb1` element into a flexbox parent. Use the `flex-direction` and `align-items` properties to center the children.
|
||||
|
||||
# --hints--
|
||||
|
||||
|
||||
+2
-2
@@ -13,13 +13,13 @@ Usa la parola chiave `return` per restituire il valore di `hit` alla fine della
|
||||
|
||||
# --hints--
|
||||
|
||||
You should use the `return` keyword to return the value of `hit`.
|
||||
Dovresti usare la parola chiave `return` per restituire il valore di `hit`.
|
||||
|
||||
```js
|
||||
assert.match(getMonsterAttackValue, /return\s*hit/);
|
||||
```
|
||||
|
||||
Your function should return the expected value.
|
||||
La funzione dovrebbe restituire il valore atteso.
|
||||
|
||||
```js
|
||||
xp = 0;
|
||||
|
||||
+6
-6
@@ -7,11 +7,11 @@ dashedName: step-147
|
||||
|
||||
# --description--
|
||||
|
||||
If you play the game in its current state you might notice a bug. If your `xp` is high enough, the `getMonsterAttackValue` function will return a negative number, which will actually add to your total health when fighting a monster!
|
||||
Se fai il gioco nel suo stato attuale potresti notare un bug. Se `xp` è abbastanza alto, la funzione `getMonsterAttackValue` restituirà un valore negativo, che in realtà si aggiungerà alla tua vita totale quando combatti un mostro!
|
||||
|
||||
In `getMonsterAttackValue`, change `return hit` to a ternary operator that returns `hit` if `hit` is greater than `0`, or returns `0` if it is not.
|
||||
In `getMonsterAttackValue`, cambia `return hit` in un operatore ternario che restituisce `hit` se `hit` è maggiore di `0` o restituisce `0` se non lo è.
|
||||
|
||||
Here is an example of returning a value based on `condition` with a ternary:
|
||||
Ecco un esempio su come restituire un valore in base a una condizione (`condition`) con un'espressione ternaria:
|
||||
|
||||
```js
|
||||
return condition ? true : false;
|
||||
@@ -19,19 +19,19 @@ return condition ? true : false;
|
||||
|
||||
# --hints--
|
||||
|
||||
You should use a ternary to change the `return` value if `hit` is greater than `0`.
|
||||
Dovresti usare un ternario per cambiare il valore dato dal `return` se `hit` è maggiore di `0`.
|
||||
|
||||
```js
|
||||
assert.match(getMonsterAttackValue.toString(), /return\s+hit\s*>\s*0/);
|
||||
```
|
||||
|
||||
You should use a ternary to return `hit` if `hit` is greater than `0`
|
||||
Dovresti usare un ternario per restituire `hit` se `hit` è maggiore di `0`
|
||||
|
||||
```js
|
||||
assert.match(getMonsterAttackValue.toString(), /return\s+hit\s*>\s*0\s*\?\s*hit/);
|
||||
```
|
||||
|
||||
You should use a ternary to return `0` if `hit` is not greater than `0`.
|
||||
Dovresti usare un ternario per restituire `0` se `hit` non è maggiore di `0`.
|
||||
|
||||
```js
|
||||
assert.match(getMonsterAttackValue.toString(), /return\s+hit\s*>\s*0\s*\?\s*hit\s*:\s*0/);
|
||||
|
||||
+2
-2
@@ -7,11 +7,11 @@ dashedName: step-148
|
||||
|
||||
# --description--
|
||||
|
||||
In your `attack` function, below the `health` variable create an `if` statement. Set the condition to call the `isMonsterHit` function.
|
||||
Nella funzione `attack`, sotto la variabile `health`, crea un'istruzione `if`. Imposta la condizione in modo che chiami la funzione `isMonsterHit`.
|
||||
|
||||
# --hints--
|
||||
|
||||
You should add an `if` statement which calls `isMonsterHit` in the condition.
|
||||
Dovresti aggiungere un'istruzione `if` che chiama `isMonsterHit` nella condizione.
|
||||
|
||||
```js
|
||||
assert.match(attack.toString(), /if\s*\(\s*isMonsterHit\s*\(\s*\)/)
|
||||
|
||||
+2
-2
@@ -7,11 +7,11 @@ dashedName: step-149
|
||||
|
||||
# --description--
|
||||
|
||||
Move your `monsterHealth` assignment into your `if` block.
|
||||
Sposta l'assegnazione di `monsterHealth` nel blocco `if`.
|
||||
|
||||
# --hints--
|
||||
|
||||
You should move your `monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1` into your `if` block.
|
||||
Dovresti spostare `monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1` nel blocco `if`.
|
||||
|
||||
```js
|
||||
assert.match(attack.toString(), /if\s*\(isMonsterHit\(\)\s*\)\s*\{\s*monsterHealth\s*-=\s*weapons\[currentWeapon\]\.power\s*\+\s*Math\.floor\(Math\.random\(\)\s*\*\s*xp\)\s*\+\s*1/)
|
||||
|
||||
+3
-3
@@ -7,17 +7,17 @@ dashedName: step-150
|
||||
|
||||
# --description--
|
||||
|
||||
Add an `else` statement to your `if` statement. In the `else` statement, use the `+=` operator to add the text `You miss.` to the end of `text.innerText`.
|
||||
Aggiungi un'istruzione `else` all'istruzione `if`. Nell'istruzione `else`, usa l'operatore `+=` per aggiungere il testo `You miss.` alla fine di `text.innerText`.
|
||||
|
||||
# --hints--
|
||||
|
||||
You should add an `else` block after your `if (isMonsterHit())` block.
|
||||
Dovresti aggiungere un blocco `else` dopo il blocco `if (isMonsterHit())`.
|
||||
|
||||
```js
|
||||
assert.match(attack.toString(), /if\s*\(isMonsterHit\(\)\s*\)\s*\{\s*monsterHealth\s*-=\s*weapons\[currentWeapon\]\.power\s*\+\s*Math\.floor\(Math\.random\(\)\s*\*\s*xp\)\s*\+\s*1;\s*\}\s*else/)
|
||||
```
|
||||
|
||||
You should add the text `You miss.` to the end of `text.innerText`. Remember to use compound assignment.
|
||||
Dovresti aggiungere il testo `You miss.` alla fine di `text.innerText`. Ricordati di usare l'assegnazione composta.
|
||||
|
||||
```js
|
||||
assert.match(attack.toString(), /if\s*\(isMonsterHit\(\)\s*\)\s*\{\s*monsterHealth\s*-=\s*weapons\[currentWeapon\]\.power\s*\+\s*Math\.floor\(Math\.random\(\)\s*\*\s*xp\)\s*\+\s*1;\s*\}\s*else\s*\{\s*text\.innerText\s*\+=\s*('|")\sYou miss\.\1/)
|
||||
|
||||
+3
-3
@@ -7,17 +7,17 @@ dashedName: step-151
|
||||
|
||||
# --description--
|
||||
|
||||
Now create the `isMonsterHit` function. This will return a <dfn>boolean</dfn> value (true or false) to be used in your `if` statement. Return the result of the comparison `Math.random() > .2`.
|
||||
Adesso crea la funzione `isMonsterHit`. Restituirà un valore <dfn>booleano</dfn> (true o false) da usare nell'istruzione `if`. Restituisci il risultato del confronto `Math.random() > .2`.
|
||||
|
||||
# --hints--
|
||||
|
||||
You should use the `function` keyword to declare `isMonsterHit`.
|
||||
Dovresti usare la parola chiave `function` per dichiarare `isMonsterHit`.
|
||||
|
||||
```js
|
||||
assert.match(code, /function\s+isMonsterHit/);
|
||||
```
|
||||
|
||||
Your `isMonsterHit` function should return the result of the comparison `Math.random() > .2`.
|
||||
La funzione `isMonsterHit` dovrebbe restituire il risultato del confronto `Math.random() > .2`.
|
||||
|
||||
```js
|
||||
assert.match(isMonsterHit.toString(), /return\s*Math\.random\(\)\s*>\s*0?\.2/);
|
||||
|
||||
+6
-6
@@ -7,27 +7,27 @@ dashedName: step-152
|
||||
|
||||
# --description--
|
||||
|
||||
The player should hit if either `Math.random() > .2` **or** if the player's health is less than 20. At the end of your `return` statement, use the <dfn>logical or</dfn> operator `||` and check if `health` is less than `20`.
|
||||
Il giocatore dovrebbe colpire se `Math.random() > .2` **o** se la vita del giocatore è minore di 20. Alla fine dell'istruzione `return`, usa l'operatore <dfn>logico or</dfn>, `||`, e verifica se `health` è minore di `20`.
|
||||
|
||||
The logical or operator will use the first value if it is truthy, otherwise it will use the second value.
|
||||
L'operatore logico or userà il primo valore se è vero, altrimenti userà il secondo valore.
|
||||
|
||||
For example: `num < 10 || num > 20`.
|
||||
Ad esempio: `num < 10 || num > 20`.
|
||||
|
||||
# --hints--
|
||||
|
||||
Your `isMonsterHit` function should use the logical or operator.
|
||||
La funzione `isMonsterHit` dovrebbe usare l'operatore logico or.
|
||||
|
||||
```js
|
||||
assert.match(isMonsterHit.toString(), /\|\|/);
|
||||
```
|
||||
|
||||
Your logical or operator should use `health < 20` as the fallback value.
|
||||
L'operatore logico or dovrebbe usare `health < 20` come valore di fallback.
|
||||
|
||||
```js
|
||||
assert.match(isMonsterHit.toString(), /\|\|\s*health\s*<\s*20/);
|
||||
```
|
||||
|
||||
Your function should return the result of the comparison `Math.random() > .2` **or** `health < 20`.
|
||||
La funzione dovrebbe restituire il risultato del confronto `Math.random() > .2` **or** `health < 20`.
|
||||
|
||||
```js
|
||||
assert.match(isMonsterHit.toString(), /return\s*Math\.random\(\)\s*>\s*0?\.2\s*\|\|\s*health\s*<\s*20/);
|
||||
|
||||
+3
-3
@@ -7,18 +7,18 @@ dashedName: step-153
|
||||
|
||||
# --description--
|
||||
|
||||
On every attack, there should be a chance that the player's weapon breaks. At the end of the `attack` function, add an empty `if` expression with the condition `Math.random() <= .1`.
|
||||
In ogni attacco, dovrebbe esserci la possibilità che l'arma del giocatore si rompa. Alla fine della funzione `attack`, aggiungi un'espressione `if` vuota con la condizione `Math.random() <= .1`.
|
||||
|
||||
# --hints--
|
||||
|
||||
You should add an `if` statement to your `attack` function.
|
||||
Dovresti aggiungere un'istruzione `if` alla funzione `attack`.
|
||||
|
||||
```js
|
||||
const ifs = attack.toString().match(/if/g);
|
||||
assert.lengthOf(ifs, 4);
|
||||
```
|
||||
|
||||
Your new `if` statement should check `Math.random() <= .1`.
|
||||
La nuova istruzione `if` dovrebbe verificare se `Math.random() <= .1`.
|
||||
|
||||
```js
|
||||
assert.match(attack.toString(), /if\s*\(\s*Math\.random\(\)\s*<=\s*0?\.1\s*\)/);
|
||||
|
||||
+6
-6
@@ -7,37 +7,37 @@ dashedName: step-154
|
||||
|
||||
# --description--
|
||||
|
||||
Use the `+=` operator to add `Your [weapon] breaks.` to the end of `text.innerText`, replacing `weapon` with the last item in the `inventory` array. You can get this last item by using `inventory.pop()`, which will remove the last item in the array AND return it so it appears in your string.
|
||||
Usa l'operatore `+=` per aggiungere `Your [weapon] breaks.` alla fine di `text.innerText`, sostituendo `weapon` con l'ultimo elemento nell'array `inventory`. Puoi ottenere l'ultimo elemento con `inventory.pop()`, che rimuove l'ultimo elemento nell'array E lo restituisce, così che appaia nella stringa.
|
||||
|
||||
# --hints--
|
||||
|
||||
You should use the compound assignment operator to modify `text.innerText`.
|
||||
Dovresti usare l'operatore di assegnazione composta per modificare `text.innerText`.
|
||||
|
||||
```js
|
||||
const concat = attack.toString().match(/\+=/g);
|
||||
assert.lengthOf(concat, 3);
|
||||
```
|
||||
|
||||
You should use the `pop` method on the `inventory` array.
|
||||
Dovresti usare il metodo `pop` sull'array `inventory`.
|
||||
|
||||
```js
|
||||
assert.match(attack.toString(), /inventory\.pop\(\)/);
|
||||
```
|
||||
|
||||
You should add the string " Your " to `text.innerText`. Remember that spacing matters.
|
||||
Dovresti aggiungere la stringa " Your " a `text.innerText`. Ricorda che la spaziatura è importante.
|
||||
|
||||
```js
|
||||
assert.match(attack.toString(), /text\.innerText\s*\+=\s*('|")\sYour\s\1/);
|
||||
```
|
||||
|
||||
You should add the return value of `inventory.pop()` to the `Your` string.
|
||||
Dovresti aggiungere il valore di ritorno di `inventory.pop()` alla stringa `Your`.
|
||||
|
||||
```js
|
||||
console.log(attack.toString());
|
||||
assert.match(attack.toString(), /text\.innerText\s*\+=\s*('|")\sYour\s\1\s*\+\s*inventory\.pop\(\)/);
|
||||
```
|
||||
|
||||
You should add `breaks.` to the `"Your " + inventory.pop()` string.
|
||||
Dovresti aggiungere `breaks.` alla stringa `"Your " + inventory.pop()`.
|
||||
|
||||
```js
|
||||
assert.match(attack.toString(), /text\.innerText\s*\+=\s*('|")\sYour\s\1\s*\+\s*inventory\.pop\(\)\s*\+\s*('|")\sbreaks\.\2/);
|
||||
|
||||
+4
-4
@@ -7,19 +7,19 @@ dashedName: step-155
|
||||
|
||||
# --description--
|
||||
|
||||
Remember that the increment operator `++` can be used to increase a variable's value by 1. There is also a <dfn>decrement operator</dfn> `--` that can be used to decrease a variable's value by 1.
|
||||
Ricorda che l'operatore di incremento `++` può essere usato per aumentare il valore di una variabile di 1. Esiste anche l'<dfn>operatore di decremento</dfn> `--` che può essere usato per diminuire il valore di una variabile di 1.
|
||||
|
||||
Decrement the value of `currentWeapon` in your `if` statement, after you update the text.
|
||||
Decrementa il valore di `currentWeapon` nell'istruzione `if`, dopo l'aggiornamento del testo.
|
||||
|
||||
# --hints--
|
||||
|
||||
You should use the decrement operator.
|
||||
Dovresti usare l'operatore di decremento.
|
||||
|
||||
```js
|
||||
assert.match(attack.toString(), /--/);
|
||||
```
|
||||
|
||||
You should decrement `currentWeapon` in your `if` statement.
|
||||
Dovresti decrementare `currentWeapon` nell'istruzione `if`.
|
||||
|
||||
```js
|
||||
assert.match(attack.toString(), /currentWeapon\s*--/);
|
||||
|
||||
+6
-6
@@ -7,11 +7,11 @@ dashedName: step-156
|
||||
|
||||
# --description--
|
||||
|
||||
We don't want a player's only weapon to break. The logical or operator checks if two statements are true.
|
||||
Non vogliamo che l'unica arma di un giocatore si rompa. The logical or operator checks if two statements are true.
|
||||
|
||||
Use the <dfn>logical and</dfn> operator `&&` to add a second condition to your `if` statement. The player's weapon should only break if `inventory.length` does not equal (`!==`) one.
|
||||
Usa l'operatore <dfn>logico and</dfn>, `&&`, per aggiungere una seconda condizione all'istruzione `if`. L'arma del giocatore dovrebbe rompersi solo se `inventory.length` non è uguale (`!==`) a uno.
|
||||
|
||||
Here is an example of an `if` statement with two conditions:
|
||||
Ecco un esempio di istruzione `if` con due condizioni:
|
||||
|
||||
```js
|
||||
if (firstName === "Quincy" && lastName === "Larson") {
|
||||
@@ -21,19 +21,19 @@ if (firstName === "Quincy" && lastName === "Larson") {
|
||||
|
||||
# --hints--
|
||||
|
||||
You should not modify your existing `if` statement.
|
||||
Non dovresti modificare l'istruzione `if` esistente.
|
||||
|
||||
```js
|
||||
assert.match(attack.toString(), /if\s*\(Math\.random\(\)\s*\<=\s*\.1/);
|
||||
```
|
||||
|
||||
You should use the logical and operator `&&`.
|
||||
Dovresti usare l'operatore logico `&&`.
|
||||
|
||||
```js
|
||||
assert.match(attack.toString(), /if\s*\(Math\.random\(\)\s*\<=\s*\.1\s*&&/);
|
||||
```
|
||||
|
||||
You should use the logical and operator to check if `inventory.length` does not equal `1`.
|
||||
Dovresti usare l'operatore logico and per verificare se `inventory.length` non è uguale a `1`.
|
||||
|
||||
```js
|
||||
assert.match(attack.toString(), /if\s*\(Math\.random\(\)\s*\<=\s*\.1\s*&&\s*inventory\.length\s*\!\=\=\s*1\s*\)/);
|
||||
|
||||
+5
-5
@@ -7,25 +7,25 @@ dashedName: step-157
|
||||
|
||||
# --description--
|
||||
|
||||
Now you can add a small easter egg (hidden feature) to your game.
|
||||
Ora puoi aggiungere un piccolo easter egg (funzionalità nascosta, letteralmente uovo di pasqua) al gioco.
|
||||
|
||||
Create a new function called `easterEgg` which calls the `update` function with `locations[7]` as the argument.
|
||||
Crea una nuova funzione chiamata `easterEgg` che chiama la funzione `update` con `locations[7]` come argomento.
|
||||
|
||||
# --hints--
|
||||
|
||||
You should use the `function` keyword to declare `easterEgg`.
|
||||
Dovresti usare la parola chiave `function` per dichiarare `easterEgg`.
|
||||
|
||||
```js
|
||||
assert.match(code, /function\s+easterEgg\s*/);
|
||||
```
|
||||
|
||||
`easterEgg` should call the `update` function.
|
||||
`easterEgg` dovrebbe chiamare la funzione `update`.
|
||||
|
||||
```js
|
||||
assert.match(easterEgg.toString(), /update\(/);
|
||||
```
|
||||
|
||||
`easterEgg` should call the `update` function with `locations[7]` as the argument.
|
||||
`easterEgg`dovrebbe chiamare la funzione `update` con `locations[7]` come argomento.
|
||||
|
||||
```js
|
||||
assert.match(easterEgg.toString(), /update\(\s*locations\[7\]\s*\)/);
|
||||
|
||||
+3
-3
@@ -7,17 +7,17 @@ dashedName: step-158
|
||||
|
||||
# --description--
|
||||
|
||||
Create an empty `pick` function with a parameter named `guess`.
|
||||
Crea una funzione vuota `pick` con un parametro chiamato `guess`.
|
||||
|
||||
# --hints--
|
||||
|
||||
You should use the `function` keyword to declare `pick`.
|
||||
Dovresti usare la parola chiave `function` per dichiarare `pick`.
|
||||
|
||||
```js
|
||||
assert.match(code, /function\s+pick\s*/);
|
||||
```
|
||||
|
||||
`pick` should take a parameter named `guess`.
|
||||
`pick` dovrebbe prendere un parametro chiamato `guess`.
|
||||
|
||||
```js
|
||||
assert.match(pick.toString(), /pick\s*\(\s*guess\s*\)/);
|
||||
|
||||
+8
-8
@@ -7,43 +7,43 @@ dashedName: step-159
|
||||
|
||||
# --description--
|
||||
|
||||
Create two new functions named `pickTwo` and `pickEight`.
|
||||
Crea due nuove funzioni chiamate `pickTwo` e `pickEight`.
|
||||
|
||||
Inside each of those, call the `pick()` function and pass either `2` or `8` as the argument depending on the function name.
|
||||
All'interno di ognuna, chiama la funzione `pick()` passando `2` o `8` come argomento a seconda del nome della funzione.
|
||||
|
||||
# --hints--
|
||||
|
||||
You should use the `function` keyword to declare `pickTwo`.
|
||||
Dovresti usare la parola chiave `function` per dichiarare `pickTwo`.
|
||||
|
||||
```js
|
||||
assert.match(code, /function\s+pickTwo\s*/);
|
||||
```
|
||||
|
||||
You should use the `function` keyword to declare `pickEight`.
|
||||
Dovresti usare la parola chiave `function` per dichiarare `pickEight`.
|
||||
|
||||
```js
|
||||
assert.match(code, /function\s+pickEight\s*/);
|
||||
```
|
||||
|
||||
`pickTwo` should call the `pick` function.
|
||||
`pickTwo` dovrebbe chiamare la funzione `pick`.
|
||||
|
||||
```js
|
||||
assert.match(pickTwo.toString(), /pick\(/);
|
||||
```
|
||||
|
||||
`pickTwo` should call the `pick` function with `2` as the argument.
|
||||
`pickTwo` dovrebbe chiamare la funzione `pick` con `2` come argomento.
|
||||
|
||||
```js
|
||||
assert.match(pickTwo.toString(), /pick\(\s*2\s*\)/);
|
||||
```
|
||||
|
||||
`pickEight` should call the `pick` function.
|
||||
`pickEight` dovrebbe chiamare la funzione `pick`.
|
||||
|
||||
```js
|
||||
assert.match(pickEight.toString(), /pick\(/);
|
||||
```
|
||||
|
||||
`pickEight` should call the `pick` function with `8` as the argument.
|
||||
`pickEight` dovrebbe chiamare la funzione `pick` con `8` come argomento.
|
||||
|
||||
```js
|
||||
assert.match(pickEight.toString(), /pick\(\s*8\s*\)/);
|
||||
|
||||
+6
-6
@@ -7,35 +7,35 @@ dashedName: step-160
|
||||
|
||||
# --description--
|
||||
|
||||
Add another object to your `locations` array. Set `name` to `easter egg`, set `button text` to an array with the strings `2`, `8`, and `Go to town square?`, set `button functions` to an array with the variables `pickTwo`, `pickEight`, and `goTown`, and `text` to `You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!`.
|
||||
Aggiungi un altro oggetto all'array `locations`. Set `name` to `easter egg`, set `button text` to an array with the strings `2`, `8`, and `Go to town square?`, set `button functions` to an array with the variables `pickTwo`, `pickEight`, and `goTown`, and `text` to `You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!`.
|
||||
|
||||
# --hints--
|
||||
|
||||
Your `locations` array should have 8 values.
|
||||
L'array `locations` dovrebbe contenere 8 valori.
|
||||
|
||||
```js
|
||||
assert.lengthOf(locations, 8);
|
||||
```
|
||||
|
||||
Your eighth `locations` value should be an object.
|
||||
L'ottavo valore di `locations` dovrebbe essere un oggetto.
|
||||
|
||||
```js
|
||||
assert.isObject(locations[7]);
|
||||
```
|
||||
|
||||
Your eighth `locations` value should have a `name` property with the value `easter egg`.
|
||||
L'ottavo valore di `locations` dovrebbe avere una proprietà `name` con il valore `easter egg`.
|
||||
|
||||
```js
|
||||
assert.equal(locations[7].name, "easter egg");
|
||||
```
|
||||
|
||||
Your eighth `locations` value should have a `button text` property with the value an array with the strings `2`, `8`, and `Go to town square?`.
|
||||
L'ottavo valore di `locations` dovrebbe avere una proprietà `button text` con il valore di un array con le stringhe `2`, `8` e `Go to town square?`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(locations[7]["button text"], ["2", "8", "Go to town square?"]);
|
||||
```
|
||||
|
||||
Your eighth `locations` value should have a `button functions` property with the value an array with the variables `pickTwo`, `pickEight`, and `goTown`.
|
||||
L'ottavo valore di `locations` dovrebbe avere una proprietà `button functions` con il valore di un array con le variabili `pickTwo`, `pickEight` e `goTown`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(locations[7]["button functions"], [pickTwo, pickEight, goTown]);
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ dashedName: step-161
|
||||
|
||||
# --description--
|
||||
|
||||
Inside `pick`, use `let` to initialize a variable named `numbers` and set it to an empty array.
|
||||
All'interno di `pick`, usa `let` per inizializzare una variabile chiamata `numbers` e impostala su un array vuoto.
|
||||
|
||||
# --hints--
|
||||
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ dashedName: step-174
|
||||
|
||||
# --description--
|
||||
|
||||
Since you subtracted health from the player, you need to check `if` the player's `health` is less than or equal to `0`. If it is, call the `lose` function.
|
||||
Since you subtracted health from the player, you need to check if the player's `health` is less than or equal to `0`. If it is, call the `lose` function.
|
||||
|
||||
# --hints--
|
||||
|
||||
|
||||
+30
-10
@@ -87,6 +87,21 @@ assert(
|
||||
The `remove` method should remove the greatest element from the max heap while maintaining the max heap property.
|
||||
|
||||
```js
|
||||
function isHeap(arr, i, n) {
|
||||
if (i >= (n - 1) / 2) {
|
||||
return true;
|
||||
}
|
||||
if (
|
||||
arr[i] >= arr[2 * i + 1] &&
|
||||
arr[i] >= arr[2 * i + 2] &&
|
||||
isHeap(arr, 2 * i + 1, n) &&
|
||||
isHeap(arr, 2 * i + 2, n)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
assert(
|
||||
(function () {
|
||||
var test = false;
|
||||
@@ -95,16 +110,21 @@ assert(
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
test.insert(30);
|
||||
test.insert(300);
|
||||
test.insert(500);
|
||||
test.insert(10);
|
||||
let result = [];
|
||||
result.push(test.remove());
|
||||
result.push(test.remove());
|
||||
result.push(test.remove());
|
||||
result.push(test.remove());
|
||||
return result.join('') == '5003003010';
|
||||
let max = Infinity;
|
||||
const [result, vals] = [[], [2, 15, 3, 7, 12, 7, 10, 90]];
|
||||
vals.forEach((val) => test.insert(val));
|
||||
for (let i = 0; i < vals.length; i++) {
|
||||
const curHeap = test.print();
|
||||
const arr = curHeap[0] === null ? curHeap.slice(1) : curHeap;
|
||||
if (!isHeap(arr, 0, arr.length - 1)) {
|
||||
return false;
|
||||
}
|
||||
const removed = test.remove();
|
||||
if(removed > max) return false
|
||||
max = removed;
|
||||
result.push(removed);
|
||||
}
|
||||
return true
|
||||
})()
|
||||
);
|
||||
```
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ dashedName: step-13
|
||||
|
||||
# --description--
|
||||
|
||||
`.bb1` の要素のスタイルプロパティとして、`display: flex;`、`flex-direction: column;`、`align-items: center;` を設定してください。 この設定により「フレックス」または「フレックスボックス」と呼ばれる方法で、ビルのパーツが中央に配置されます。 フレックスボックスについては別のプロジェクトで詳しく学習します。
|
||||
Center the parts of your building by turning the `.bb1` element into a flexbox parent. Use the `flex-direction` and `align-items` properties to center the children.
|
||||
|
||||
# --hints--
|
||||
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ dashedName: step-174
|
||||
|
||||
# --description--
|
||||
|
||||
Since you subtracted health from the player, you need to check `if` the player's `health` is less than or equal to `0`. If it is, call the `lose` function.
|
||||
Since you subtracted health from the player, you need to check if the player's `health` is less than or equal to `0`. If it is, call the `lose` function.
|
||||
|
||||
# --hints--
|
||||
|
||||
|
||||
+30
-10
@@ -87,6 +87,21 @@ assert(
|
||||
O método `remove` deve remover o maior elemento do Max Heap ao mesmo tempo em que mantém a propriedade do Max Heap.
|
||||
|
||||
```js
|
||||
function isHeap(arr, i, n) {
|
||||
if (i >= (n - 1) / 2) {
|
||||
return true;
|
||||
}
|
||||
if (
|
||||
arr[i] >= arr[2 * i + 1] &&
|
||||
arr[i] >= arr[2 * i + 2] &&
|
||||
isHeap(arr, 2 * i + 1, n) &&
|
||||
isHeap(arr, 2 * i + 2, n)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
assert(
|
||||
(function () {
|
||||
var test = false;
|
||||
@@ -95,16 +110,21 @@ assert(
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
test.insert(30);
|
||||
test.insert(300);
|
||||
test.insert(500);
|
||||
test.insert(10);
|
||||
let result = [];
|
||||
result.push(test.remove());
|
||||
result.push(test.remove());
|
||||
result.push(test.remove());
|
||||
result.push(test.remove());
|
||||
return result.join('') == '5003003010';
|
||||
let max = Infinity;
|
||||
const [result, vals] = [[], [2, 15, 3, 7, 12, 7, 10, 90]];
|
||||
vals.forEach((val) => test.insert(val));
|
||||
for (let i = 0; i < vals.length; i++) {
|
||||
const curHeap = test.print();
|
||||
const arr = curHeap[0] === null ? curHeap.slice(1) : curHeap;
|
||||
if (!isHeap(arr, 0, arr.length - 1)) {
|
||||
return false;
|
||||
}
|
||||
const removed = test.remove();
|
||||
if(removed > max) return false
|
||||
max = removed;
|
||||
result.push(removed);
|
||||
}
|
||||
return true
|
||||
})()
|
||||
);
|
||||
```
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ dashedName: step-13
|
||||
|
||||
# --description--
|
||||
|
||||
Dê ao elemento `.bb1` estas propriedades de estilo: `display: flex;`, `flex-direction: column;` e `align-items: center;`. Isto centralizará as partes do edifício usando "flex" ou "flexbox". Você aprenderá sobre isso com mais detalhes em outro projeto.
|
||||
Centralize as partes do seu edifício transformando o elemento `.bb1` em um elemento pai do flexbox. Use as propriedades `flex-direction` e `align-items` para centralizar os elementos filhos.
|
||||
|
||||
# --hints--
|
||||
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ dashedName: step-174
|
||||
|
||||
# --description--
|
||||
|
||||
Since you subtracted health from the player, you need to check `if` the player's `health` is less than or equal to `0`. If it is, call the `lose` function.
|
||||
Since you subtracted health from the player, you need to check if the player's `health` is less than or equal to `0`. If it is, call the `lose` function.
|
||||
|
||||
# --hints--
|
||||
|
||||
|
||||
+30
-10
@@ -87,6 +87,21 @@ assert(
|
||||
The `remove` method should remove the greatest element from the max heap while maintaining the max heap property.
|
||||
|
||||
```js
|
||||
function isHeap(arr, i, n) {
|
||||
if (i >= (n - 1) / 2) {
|
||||
return true;
|
||||
}
|
||||
if (
|
||||
arr[i] >= arr[2 * i + 1] &&
|
||||
arr[i] >= arr[2 * i + 2] &&
|
||||
isHeap(arr, 2 * i + 1, n) &&
|
||||
isHeap(arr, 2 * i + 2, n)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
assert(
|
||||
(function () {
|
||||
var test = false;
|
||||
@@ -95,16 +110,21 @@ assert(
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
test.insert(30);
|
||||
test.insert(300);
|
||||
test.insert(500);
|
||||
test.insert(10);
|
||||
let result = [];
|
||||
result.push(test.remove());
|
||||
result.push(test.remove());
|
||||
result.push(test.remove());
|
||||
result.push(test.remove());
|
||||
return result.join('') == '5003003010';
|
||||
let max = Infinity;
|
||||
const [result, vals] = [[], [2, 15, 3, 7, 12, 7, 10, 90]];
|
||||
vals.forEach((val) => test.insert(val));
|
||||
for (let i = 0; i < vals.length; i++) {
|
||||
const curHeap = test.print();
|
||||
const arr = curHeap[0] === null ? curHeap.slice(1) : curHeap;
|
||||
if (!isHeap(arr, 0, arr.length - 1)) {
|
||||
return false;
|
||||
}
|
||||
const removed = test.remove();
|
||||
if(removed > max) return false
|
||||
max = removed;
|
||||
result.push(removed);
|
||||
}
|
||||
return true
|
||||
})()
|
||||
);
|
||||
```
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ dashedName: step-13
|
||||
|
||||
# --description--
|
||||
|
||||
Надайте своєму елементу `.bb1` наступні властивості стилю: `display: flex;`, `flex-direction: column;` та `align-items: center;`. Це зцентрує частини будівлі з допомогою «flex» або «flexbox». Детальніше про це ви дізнаєтесь в іншому проєкті.
|
||||
Center the parts of your building by turning the `.bb1` element into a flexbox parent. Use the `flex-direction` and `align-items` properties to center the children.
|
||||
|
||||
# --hints--
|
||||
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ dashedName: step-174
|
||||
|
||||
# --description--
|
||||
|
||||
Since you subtracted health from the player, you need to check `if` the player's `health` is less than or equal to `0`. If it is, call the `lose` function.
|
||||
Since you subtracted health from the player, you need to check if the player's `health` is less than or equal to `0`. If it is, call the `lose` function.
|
||||
|
||||
# --hints--
|
||||
|
||||
|
||||
Reference in New Issue
Block a user