chore(i18n,curriculum): update translations

This commit is contained in:
camperbot
2021-10-27 15:10:57 +00:00
committed by Mrugesh Mohapatra
parent e139fbcf13
commit c1fb339bbc
539 changed files with 3319 additions and 3352 deletions

View File

@ -18,9 +18,9 @@ Gli indici degli array sono scritti nella stessa notazione tra parentesi usata d
**Esempio**
```js
var array = [50,60,70];
const array = [50, 60, 70];
array[0];
var data = array[1];
const data = array[1];
```
`array[0]` ora è `50` e `data` ha il valore `60`.
@ -76,7 +76,7 @@ if(typeof myArray !== "undefined" && typeof myData !== "undefined"){(function(y,
## --seed-contents--
```js
var myArray = [50,60,70];
const myArray = [50, 60, 70];
```
@ -84,6 +84,6 @@ var myArray = [50,60,70];
# --solutions--
```js
var myArray = [50,60,70];
var myData = myArray[0];
const myArray = [50, 60, 70];
const myData = myArray[0];
```

View File

@ -14,12 +14,13 @@ dashedName: access-multi-dimensional-arrays-with-indexes
**Esempio**
```js
var arr = [
[1,2,3],
[4,5,6],
[7,8,9],
[[10,11,12], 13, 14]
const arr = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
[[10, 11, 12], 13, 14]
];
arr[3];
arr[3][0];
arr[3][0][1];
@ -58,14 +59,19 @@ if(typeof myArray !== "undefined"){(function(){return "myData: " + myData + " my
## --seed-contents--
```js
var myArray = [[1,2,3], [4,5,6], [7,8,9], [[10,11,12], 13, 14]];
const myArray = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
[[10, 11, 12], 13, 14],
];
var myData = myArray[0][0];
const myData = myArray[0][0];
```
# --solutions--
```js
var myArray = [[1,2,3],[4,5,6], [7,8,9], [[10,11,12], 13, 14]];
var myData = myArray[2][1];
const myArray = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [[10, 11, 12], 13, 14]];
const myData = myArray[2][1];
```

View File

@ -14,7 +14,7 @@ Come abbiamo visto in precedenti esempi, gli oggetti possono contenere sia ogget
Ecco un esempio di come accedere a un array nidificato:
```js
var ourPets = [
const ourPets = [
{
animalType: "cat",
names: [
@ -32,6 +32,7 @@ var ourPets = [
]
}
];
ourPets[0].names[1];
ourPets[1].names[0];
```
@ -72,7 +73,7 @@ assert(/=\s*myPlants\[1\].list\[1\]/.test(code));
## --seed-contents--
```js
var myPlants = [
const myPlants = [
{
type: "flowers",
list: [
@ -91,13 +92,13 @@ var myPlants = [
}
];
var secondTree = "";
const secondTree = "";
```
# --solutions--
```js
var myPlants = [
const myPlants = [
{
type: "flowers",
list: [
@ -116,5 +117,5 @@ var myPlants = [
}
];
var secondTree = myPlants[1].list[1];
const secondTree = myPlants[1].list[1];
```

View File

@ -14,7 +14,7 @@ Le sotto-proprietà degli oggetti possono essere accessibili concatenando insiem
Ecco un oggetto nidificato:
```js
var ourStorage = {
const ourStorage = {
"desk": {
"drawer": "stapler"
},
@ -26,6 +26,7 @@ var ourStorage = {
"bottom drawer": "soda"
}
};
ourStorage.cabinet["top drawer"].folder2;
ourStorage.desk.drawer;
```
@ -66,7 +67,7 @@ assert(/=\s*myStorage\.car\.inside\[\s*("|')glove box\1\s*\]/g.test(code));
## --seed-contents--
```js
var myStorage = {
const myStorage = {
"car": {
"inside": {
"glove box": "maps",
@ -78,13 +79,13 @@ var myStorage = {
}
};
var gloveBoxContents = undefined;
const gloveBoxContents = undefined;
```
# --solutions--
```js
var myStorage = {
const myStorage = {
"car":{
"inside":{
"glove box":"maps",
@ -95,5 +96,5 @@ var myStorage = {
}
}
};
var gloveBoxContents = myStorage.car.inside["glove box"];
const gloveBoxContents = myStorage.car.inside["glove box"];
```

View File

@ -16,11 +16,12 @@ Tuttavia, puoi ancora usare la notazione a parentesi sulle proprietà dell'ogget
Ecco un esempio di come usare la notazione a parentesi per leggere la proprietà di un oggetto:
```js
var myObj = {
const myObj = {
"Space Name": "Kirk",
"More Space": "Spock",
"NoSpace": "USS Enterprise"
};
myObj["Space Name"];
myObj['More Space'];
myObj["NoSpace"];
@ -78,26 +79,25 @@ assert(code.match(/testObj\s*?\[('|")[^'"]+\1\]/g).length > 1);
```js
// Setup
var testObj = {
const testObj = {
"an entree": "hamburger",
"my side": "veggies",
"the drink": "water"
};
// Only change code below this line
var entreeValue = testObj; // Change this line
var drinkValue = testObj; // Change this line
const entreeValue = testObj; // Change this line
const drinkValue = testObj; // Change this line
```
# --solutions--
```js
var testObj = {
const testObj = {
"an entree": "hamburger",
"my side": "veggies",
"the drink": "water"
};
var entreeValue = testObj["an entree"];
var drinkValue = testObj['the drink'];
const entreeValue = testObj["an entree"];
const drinkValue = testObj['the drink'];
```

View File

@ -16,15 +16,17 @@ La notazione a punti è quella che usi quando conosci già il nome della proprie
Di seguito è riportato un esempio di utilizzo della notazione a punti (`.`) per leggere la proprietà di un oggetto:
```js
var myObj = {
const myObj = {
prop1: "val1",
prop2: "val2"
};
var prop1val = myObj.prop1;
var prop2val = myObj.prop2;
const prop1val = myObj.prop1;
const prop2val = myObj.prop2;
```
`prop1val` ha il valore della stringa `val1` e `prop2val` ha il avere un valore della stringa `val2`.
# --instructions--
Leggi i valori delle proprietà di `testObj` utilizzando la notazione a punti. Imposta la variabile `hatValue` in modo che sia uguale alla proprietà `hat` dell'oggetto, e imposta la variabile `shirtValue` in modo che sia uguale alla proprietà `shirt` dell'oggetto.
@ -73,27 +75,26 @@ assert(code.match(/testObj\.\w+/g).length > 1);
```js
// Setup
var testObj = {
const testObj = {
"hat": "ballcap",
"shirt": "jersey",
"shoes": "cleats"
};
// Only change code below this line
var hatValue = testObj; // Change this line
var shirtValue = testObj; // Change this line
const hatValue = testObj; // Change this line
const shirtValue = testObj; // Change this line
```
# --solutions--
```js
var testObj = {
const testObj = {
"hat": "ballcap",
"shirt": "jersey",
"shoes": "cleats"
};
var hatValue = testObj.hat;
var shirtValue = testObj.shirt;
const hatValue = testObj.hat;
const shirtValue = testObj.shirt;
```

View File

@ -14,11 +14,14 @@ Un altro uso della notazione a parentesi con gli oggetti è quello di accedere a
Ecco un esempio di utilizzo di una variabile per accedere a una proprietà:
```js
var dogs = {
Fido: "Mutt", Hunter: "Doberman", Snoopie: "Beagle"
const dogs = {
Fido: "Mutt",
Hunter: "Doberman",
Snoopie: "Beagle"
};
var myDog = "Hunter";
var myBreed = dogs[myDog];
const myDog = "Hunter";
const myBreed = dogs[myDog];
console.log(myBreed);
```
@ -27,14 +30,16 @@ La stringa `Doberman` sarà visualizzata nella console.
Un altro modo per utilizzare questo concetto è quando il nome della proprietà viene ottenuto dinamicamente durante l'esecuzione del programma, come segue:
```js
var someObj = {
const someObj = {
propName: "John"
};
function propPrefix(str) {
var s = "prop";
const s = "prop";
return s + str;
}
var someProp = propPrefix("Name");
const someProp = propPrefix("Name");
console.log(someObj[someProp]);
```
@ -96,26 +101,25 @@ if(typeof player !== "undefined"){(function(v){return v;})(player);}
```js
// Setup
var testObj = {
const testObj = {
12: "Namath",
16: "Montana",
19: "Unitas"
};
// Only change code below this line
var playerNumber; // Change this line
var player = testObj; // Change this line
const playerNumber = 42; // Change this line
const player = testObj; // Change this line
```
# --solutions--
```js
var testObj = {
const testObj = {
12: "Namath",
16: "Montana",
19: "Unitas"
};
var playerNumber = 16;
var player = testObj[playerNumber];
const playerNumber = 16;
const player = testObj[playerNumber];
```

View File

@ -28,7 +28,7 @@ Ora quando valuteremo `ourDog.bark`, otterremo il suo abbaiare, `bow-wow`.
Esempio:
```js
var ourDog = {
const ourDog = {
"name": "Camper",
"legs": 4,
"tails": 1,
@ -67,7 +67,7 @@ assert(!/bark[^\n]:/.test(code));
## --seed-contents--
```js
var myDog = {
const myDog = {
"name": "Happy Coder",
"legs": 4,
"tails": 1,
@ -80,7 +80,7 @@ var myDog = {
# --solutions--
```js
var myDog = {
const myDog = {
"name": "Happy Coder",
"legs": 4,
"tails": 1,

View File

@ -18,7 +18,7 @@ JavaScript utilizza il simbolo `+` come operatore di addizione quando è posizio
**Esempio:**
```js
myVar = 5 + 10;
const myVar = 5 + 10;
```
`myVar` ora ha il valore `15`.
@ -52,11 +52,11 @@ assert(/\+/.test(code));
## --seed-contents--
```js
var sum = 10 + 0;
const sum = 10 + 0;
```
# --solutions--
```js
var sum = 10 + 10;
const sum = 10 + 10;
```

View File

@ -92,7 +92,7 @@ assert(code.match(/break/g).length > 2);
```js
function switchOfStuff(val) {
var answer = "";
let answer = "";
// Only change code below this line
@ -108,7 +108,7 @@ switchOfStuff(1);
```js
function switchOfStuff(val) {
var answer = "";
let answer = "";
switch(val) {
case "a":

View File

@ -14,8 +14,8 @@ Proprio come possiamo costruire una stringa su più righe di stringhe <dfn>lette
Esempio:
```js
var anAdjective = "awesome!";
var ourStr = "freeCodeCamp is ";
const anAdjective = "awesome!";
let ourStr = "freeCodeCamp is ";
ourStr += anAdjective;
```
@ -64,15 +64,14 @@ assert(code.match(/myStr\s*\+=\s*someAdjective\s*/).length > 0);
```js
// Change code below this line
var someAdjective;
var myStr = "Learning to code is ";
const someAdjective = "";
let myStr = "Learning to code is ";
```
# --solutions--
```js
var someAdjective = "neat";
var myStr = "Learning to code is ";
const someAdjective = "neat";
let myStr = "Learning to code is ";
myStr += someAdjective;
```

View File

@ -49,13 +49,14 @@ assert(/processed\s*=\s*processArg\(\s*7\s*\)/.test(code));
```js
// Setup
var processed = 0;
let processed = 0;
function processArg(num) {
return (num + 3) / 5;
}
// Only change code below this line
```
# --solutions--

View File

@ -18,7 +18,7 @@ Gli oggetti sono utili per archiviare i dati in modo strutturato e possono rappr
Ecco un esempio di oggetto gatto (cat):
```js
var cat = {
const cat = {
"name": "Whiskers",
"legs": 4,
"tails": 1,
@ -29,7 +29,7 @@ var cat = {
In questo esempio, tutte le proprietà sono memorizzate come stringhe, come `name`, `legs`e `tails`. Per le proprietà puoi anche usare i numeri. Puoi anche omettere le virgolette per le proprietà di tipo stringa di una sola parola, come segue:
```js
var anotherObject = {
const anotherObject = {
make: "Ford",
5: "five",
"model": "focus"
@ -139,18 +139,18 @@ assert(
## --seed-contents--
```js
var myDog = {
// Only change code below this line
const myDog = {
// Only change code below this line
// Only change code above this line
// Only change code above this line
};
```
# --solutions--
```js
var myDog = {
const myDog = {
"name": "Camper",
"legs": 4,
"tails": 1,

View File

@ -16,7 +16,7 @@ L'operatore di base è l'operatore di uguaglianza `==`. L'operatore di uguaglian
```js
function equalityTest(myVal) {
if (myVal == 10) {
return "Equal";
return "Equal";
}
return "Not Equal";
}

View File

@ -25,7 +25,7 @@ Nell'ordine, queste espressioni saranno valutate `true`, `false`, `false`, `fals
# --instructions--
Aggiungi l'operatore di disuguaglianza `!=` nell'istruzione `if` in modo che la funzione restituisca la stringa `Not Equal` quando `val` non equivale a `99`
Aggiungi l'operatore di disuguaglianza `!=` nella condizione dell' `if` in modo che la funzione restituisca la stringa `Not Equal` quando `val` non equivale a `99`.
# --hints--

View File

@ -26,7 +26,7 @@ Nel secondo esempio, `3` è un tipo `Number` e `'3'` è un tipo `String`.
# --instructions--
Usa l'operatore di uguaglianza stretta nell'istruzione `if` in modo che la funzione restituisca la stringa `Equal` quando `val` è strettamente uguale a `7`
Usa l'operatore di uguaglianza stretta nella condizione dell'`if` in modo che la funzione restituisca la stringa `Equal` quando `val` è strettamente uguale a `7`.
# --hints--

View File

@ -20,7 +20,7 @@ per aggiungere `5` a `myVar`. Poiché questo è uno scherma molto comune, ci son
Uno di questi operatori è l'operatore `+=`.
```js
var myVar = 1;
let myVar = 1;
myVar += 5;
console.log(myVar);
```
@ -61,9 +61,9 @@ Non dovresti modificare il codice sopra il commento specificato.
```js
assert(
/var a = 3;/.test(code) &&
/var b = 17;/.test(code) &&
/var c = 12;/.test(code)
/let a = 3;/.test(code) &&
/let b = 17;/.test(code) &&
/let c = 12;/.test(code)
);
```
@ -78,9 +78,9 @@ assert(
## --seed-contents--
```js
var a = 3;
var b = 17;
var c = 12;
let a = 3;
let b = 17;
let c = 12;
// Only change code below this line
a = a + 12;
@ -91,9 +91,9 @@ c = c + 7;
# --solutions--
```js
var a = 3;
var b = 17;
var c = 12;
let a = 3;
let b = 17;
let c = 12;
a += 12;
b += 9;

View File

@ -55,9 +55,9 @@ Non dovresti modificare il codice sopra il commento specificato.
```js
assert(
/var a = 48;/.test(code) &&
/var b = 108;/.test(code) &&
/var c = 33;/.test(code)
/let a = 48;/.test(code) &&
/let b = 108;/.test(code) &&
/let c = 33;/.test(code)
);
```
@ -72,9 +72,9 @@ assert(
## --seed-contents--
```js
var a = 48;
var b = 108;
var c = 33;
let a = 48;
let b = 108;
let c = 33;
// Only change code below this line
a = a / 12;
@ -85,9 +85,9 @@ c = c / 11;
# --solutions--
```js
var a = 48;
var b = 108;
var c = 33;
let a = 48;
let b = 108;
let c = 33;
a /= 12;
b /= 4;

View File

@ -55,9 +55,9 @@ Non dovresti modificare il codice sopra il commento specificato.
```js
assert(
/var a = 5;/.test(code) &&
/var b = 12;/.test(code) &&
/var c = 4\.6;/.test(code)
/let a = 5;/.test(code) &&
/let b = 12;/.test(code) &&
/let c = 4\.6;/.test(code)
);
```
@ -72,9 +72,9 @@ assert(
## --seed-contents--
```js
var a = 5;
var b = 12;
var c = 4.6;
let a = 5;
let b = 12;
let c = 4.6;
// Only change code below this line
a = a * 5;
@ -85,9 +85,9 @@ c = c * 10;
# --solutions--
```js
var a = 5;
var b = 12;
var c = 4.6;
let a = 5;
let b = 12;
let c = 4.6;
a *= 5;
b *= 3;

View File

@ -55,7 +55,7 @@ Non dovresti modificare il codice sopra il commento specificato.
```js
assert(
/var a = 11;/.test(code) && /var b = 9;/.test(code) && /var c = 3;/.test(code)
/let a = 11;/.test(code) && /let b = 9;/.test(code) && /let c = 3;/.test(code)
);
```
@ -70,9 +70,9 @@ assert(
## --seed-contents--
```js
var a = 11;
var b = 9;
var c = 3;
let a = 11;
let b = 9;
let c = 3;
// Only change code below this line
a = a - 6;
@ -83,9 +83,9 @@ c = c - 1;
# --solutions--
```js
var a = 11;
var b = 9;
var c = 3;
let a = 11;
let b = 9;
let c = 3;
a -= 6;
b -= 15;

View File

@ -22,7 +22,7 @@ In JavaScript, quando l'operatore `+` viene usato con un valore di tipo `String`
Esempio:
```js
var ourStr = "I come first. " + "I come second.";
const ourStr = "I come first. " + "I come second.";
```
La stringa `I come first. I come second.` sarebbe visualizzata nella console.
@ -44,10 +44,10 @@ Dovresti usare l'operatore `+` per costruire `myStr`.
assert(code.match(/(["']).*\1\s*\+\s*(["']).*\2/g));
```
`myStr` dovrebbe essere creato usando la parola chiave `var`.
`myStr` dovrebbe essere creato usando la parola chiave `const`.
```js
assert(/var\s+myStr/.test(code));
assert(/const\s+myStr/.test(code));
```
Dovresti assegnare il risultato alla variabile `myStr`.
@ -73,11 +73,11 @@ assert(/myStr\s*=/.test(code));
## --seed-contents--
```js
var myStr; // Change this line
const myStr = ""; // Change this line
```
# --solutions--
```js
var myStr = "This is the start. " + "This is the end.";
const myStr = "This is the start. " + "This is the end.";
```

View File

@ -16,7 +16,7 @@ Possiamo anche usare l'operatore `+=` per <dfn>concatenare</dfn> una stringa all
Esempio:
```js
var ourStr = "I come first. ";
let ourStr = "I come first. ";
ourStr += "I come second.";
```
@ -57,14 +57,12 @@ assert(code.match(/myStr\s*\+=\s*(["']).*\1/g));
## --seed-contents--
```js
// Only change code below this line
var myStr;
let myStr;
```
# --solutions--
```js
var myStr = "This is the first sentence. ";
let myStr = "This is the first sentence. ";
myStr += "This is the second sentence.";
```

View File

@ -14,8 +14,8 @@ A volte dovrai costruire una stringa, nello stile di [Mad Libs](https://en.wikip
Esempio:
```js
var ourName = "freeCodeCamp";
var ourStr = "Hello, our name is " + ourName + ", how are you?";
const ourName = "freeCodeCamp";
const ourStr = "Hello, our name is " + ourName + ", how are you?";
```
`ourStr` avrà un valore stringa `Hello, our name is freeCodeCamp, how are you?`.
@ -63,13 +63,13 @@ assert(code.match(/["']\s*\+\s*myName\s*\+\s*["']/g).length > 0);
```js
// Only change code below this line
var myName;
var myStr;
const myName = "";
const myStr = "";
```
# --solutions--
```js
var myName = "Bob";
var myStr = "My name is " + myName + " and I am well!";
const myName = "Bob";
const myStr = "My name is " + myName + " and I am well!";
```

View File

@ -16,13 +16,14 @@ Per decrementare di due ad ogni iterazione, dovremo cambiare la nostra inizializ
Inizieremo da `i = 10` e ripeteremo finché `i > 0`. Diminuiremo `i` di 2 ad ogni ciclo con `i -= 2`.
```js
var ourArray = [];
for (var i = 10; i > 0; i -= 2) {
const ourArray = [];
for (let i = 10; i > 0; i -= 2) {
ourArray.push(i);
}
```
`ourArray` adesso conterrà `[10,8,6,4,2]`. Cambiamo la nostra inizializzazione e espressione finale in modo da poter contare indietro di due per creare un array di numeri dispari discendenti.
`ourArray` adesso conterrà `[10, 8, 6, 4, 2]`. Cambiamo la nostra inizializzazione e espressione finale in modo da poter contare indietro di due per creare un array di numeri dispari discendenti.
# --instructions--
@ -42,7 +43,7 @@ Dovresti usare il metodo array `push`.
assert(code.match(/myArray.push/));
```
`myArray` dovrebbe essere uguale a `[9,7,5,3,1]`.
`myArray` dovrebbe essere uguale a `[9, 7, 5, 3, 1]`.
```js
assert.deepEqual(myArray, [9, 7, 5, 3, 1]);
@ -60,16 +61,17 @@ if(typeof myArray !== "undefined"){(function(){return myArray;})();}
```js
// Setup
var myArray = [];
const myArray = [];
// Only change code below this line
```
# --solutions--
```js
var myArray = [];
for (var i = 9; i > 0; i -= 2) {
const myArray = [];
for (let i = 9; i > 0; i -= 2) {
myArray.push(i);
}
```

View File

@ -159,7 +159,7 @@ assert(
## --seed-contents--
```js
var count = 0;
let count = 0;
function cc(card) {
// Only change code below this line
@ -175,7 +175,7 @@ cc(2); cc(3); cc(7); cc('K'); cc('A');
# --solutions--
```js
var count = 0;
let count = 0;
function cc(card) {
switch(card) {
case 2:

View File

@ -42,13 +42,14 @@ assert(myDecimal % 1 != 0);
## --seed-contents--
```js
var ourDecimal = 5.7;
const ourDecimal = 5.7;
// Only change code below this line
```
# --solutions--
```js
var myDecimal = 9.9;
const myDecimal = 9.9;
```

View File

@ -10,7 +10,7 @@ dashedName: declare-a-read-only-variable-with-the-const-keyword
La parola chiave `let` non è l'unico nuovo modo per dichiarare le variabili. In ES6, puoi anche dichiarare variabili usando la parola chiave `const`.
`const` ha tutte le fantastiche caratteristiche che ha `let`, con il il valore aggiunto che le variabili dichiarate utilizzando `const` sono di sola lettura. Esse sono un valore costante, il che significa che una volta assegnata una variabile con `const`, non può più essere riassegnata.
`const` ha tutte le fantastiche caratteristiche che ha `let`, con il il valore aggiunto che le variabili dichiarate utilizzando `const` sono di sola lettura. Esse sono un valore costante, il che significa che una volta assegnata una variabile con `const`, non può più essere riassegnata:
```js
const FAV_PET = "Cats";
@ -19,9 +19,11 @@ FAV_PET = "Dogs";
La console mostrerà un errore a causa della riassegnazione del valore di `FAV_PET`.
Come puoi vedere, cercare di riassegnare una variabile dichiarata con `const` genererà un errore. Dovresti sempre dichiarare le variabili che non vuoi riassegnare usando la parola chiave `const`. Questo aiuta quando nel caso dovessi tentare accidentalmente di riassegnare il valore a una variabile che è destinata a rimanere costante. Una pratica comune quando si dà il nome alle costanti è usare tutte le lettere maiuscole, separando le parole con un underscore.
Dovresti sempre dichiarare le variabili che non vuoi riassegnare usando la parola chiave `const`. Questo aiuta quando nel caso dovessi tentare accidentalmente di riassegnare il valore a una variabile che è destinata a rimanere costante.
**Nota:** È pratica comune per gli sviluppatori usare identificatori di variabili a lettere maiuscole per valori immutabili e a lettere minuscole o camelCase per valori mutabili (oggetti e array). In una sfida successiva vedrai un esempio di identificatore di variabile con lettere minuscole utilizzato per un array.
Una pratica comune quando si dà il nome alle costanti è usare tutte le lettere maiuscole, separando le parole con un underscore.
**Nota:** È pratica comune per gli sviluppatori usare identificatori di variabili a lettere maiuscole per valori immutabili e a lettere minuscole o camelCase per valori mutabili (oggetti e array). Imparerai di più su oggetti, array, e valori mutabili e immutabili in sfide future. In sfide future vedrai esempi di identificatori di variavile in maiuscolo, minuscolo e camelCase.
# --instructions--
@ -35,23 +37,33 @@ Modifica il codice in modo che tutte le variabili siano dichiarate utilizzando `
(getUserInput) => assert(!getUserInput('index').match(/var/g));
```
`SENTENCE` dovrebbe essere una variabile costante dichiarata con `const`.
Dovresti cambiare `fCC` a solo maiuscole.
```js
(getUserInput) => assert(getUserInput('index').match(/(const SENTENCE)/g));
(getUserInput) => {
assert(getUserInput('index').match(/(FCC)/));
assert(!getUserInput('index').match(/fCC/));
}
```
`i` dovrebbe essere dichiarata con `let`.
`FCC` dovrebbe essere una variabile costante dichiarata con `const`.
```js
(getUserInput) => assert(getUserInput('index').match(/(let i)/g));
assert.equal(FCC, 'freeCodeCamp');
assert.match(code, /const\s+FCC/);
```
`console.log` dovrebbe essere cambiato per stampare la variabile `SENTENCE`.
`fact` dovrebbe essere dichiarata con `let`.
```js
(getUserInput) => assert(getUserInput('index').match(/(let fact)/g));
```
`console.log` dovrebbe essere cambiato in modo da stampare le variabili `FCC` e `fact`.
```js
(getUserInput) =>
assert(getUserInput('index').match(/console\.log\(\s*SENTENCE\s*\)\s*;?/g));
assert(getUserInput('index').match(/console\.log\(\s*FCC\s*\,\s*fact\s*\)\s*;?/g));
```
# --seed--
@ -59,31 +71,21 @@ Modifica il codice in modo che tutte le variabili siano dichiarate utilizzando `
## --seed-contents--
```js
function printManyTimes(str) {
// Only change code below this line
var fCC = "freeCodeCamp";
var fact = "is cool!";
// Only change code above this line
// Only change code below this line
var sentence = str + " is cool!";
for (var i = 0; i < str.length; i+=2) {
console.log(sentence);
}
// Only change code above this line
}
printManyTimes("freeCodeCamp");
fact = "is awesome!";
console.log(fCC, fact);
```
# --solutions--
```js
function printManyTimes(str) {
const FCC = "freeCodeCamp";
let fact = "is cool!";
const SENTENCE = str + " is cool!";
for (let i = 0; i < str.length; i+=2) {
console.log(SENTENCE);
}
}
printManyTimes("freeCodeCamp");
fact = "is awesome!";
console.log(FCC, fact);
```

View File

@ -9,13 +9,19 @@ dashedName: declare-string-variables
# --description--
Precedentemente abbiamo usato il codice
In precedenza hai usato il seguente codice per dichiarare una variabile:
```js
var myName;
```
Ma puoi anche dichiarare una variabile con valore stringa in questo modo:
```js
var myName = "your name";
```
`"your name"` è chiamato una <dfn>stringa</dfn> <dfn>letterale</dfn>. È una stringa perché è una serie di zero o più caratteri racchiusi in virgolette singole o doppie.
`"your name"` è chiamato una <dfn>stringa</dfn> <dfn>letterale</dfn>. Una stringa letterale, o stringa, è una serie di zero o più caratteri racchiusi in virgolette singole o doppie.
# --instructions--

View File

@ -39,7 +39,7 @@ assert(myVar === 10);
```js
assert(
/var\s*myVar\s*=\s*11;\s*\/*.*\s*([-]{2}\s*myVar|myVar\s*[-]{2});/.test(code)
/let\s*myVar\s*=\s*11;\s*\/*.*\s*([-]{2}\s*myVar|myVar\s*[-]{2});/.test(code)
);
```
@ -52,7 +52,7 @@ assert(/[-]{2}\s*myVar|myVar\s*[-]{2}/.test(code));
Non dovresti modificare il codice sopra il commento specificato.
```js
assert(/var myVar = 11;/.test(code));
assert(/let myVar = 11;/.test(code));
```
# --seed--
@ -66,7 +66,7 @@ assert(/var myVar = 11;/.test(code));
## --seed-contents--
```js
var myVar = 11;
let myVar = 11;
// Only change code below this line
myVar = myVar - 1;
@ -75,6 +75,6 @@ myVar = myVar - 1;
# --solutions--
```js
var myVar = 11;
let myVar = 11;
myVar--;
```

View File

@ -18,7 +18,7 @@ delete ourDog.bark;
Esempio:
```js
var ourDog = {
const ourDog = {
"name": "Camper",
"legs": 4,
"tails": 1,
@ -70,7 +70,7 @@ assert(code.match(/"tails": 1/g).length > 0);
```js
// Setup
var myDog = {
const myDog = {
"name": "Happy Coder",
"legs": 4,
"tails": 1,
@ -79,12 +79,13 @@ var myDog = {
};
// Only change code below this line
```
# --solutions--
```js
var myDog = {
const myDog = {
"name": "Happy Coder",
"legs": 4,
"tails": 1,

View File

@ -46,11 +46,11 @@ assert(code.match(/quotient/g).length === 1);
## --seed-contents--
```js
var quotient = 0.0 / 2.0; // Change this line
const quotient = 0.0 / 2.0; // Change this line
```
# --solutions--
```js
var quotient = 4.4 / 2.0;
const quotient = 4.4 / 2.0;
```

View File

@ -16,7 +16,7 @@ JavaScript utilizza il simbolo `/` per la divisione.
**Esempio**
```js
myVar = 16 / 2;
const myVar = 16 / 2;
```
`myVar` ora ha il valore `8`.
@ -49,11 +49,11 @@ assert(/\d+\s*\/\s*\d+/.test(code));
## --seed-contents--
```js
var quotient = 66 / 0;
const quotient = 66 / 0;
```
# --solutions--
```js
var quotient = 66 / 33;
const quotient = 66 / 33;
```

View File

@ -89,11 +89,11 @@ console.log('myStr:\n' + myStr);}})();
## --seed-contents--
```js
var myStr; // Change this line
const myStr = ""; // Change this line
```
# --solutions--
```js
var myStr = "FirstLine\n\t\\SecondLine\nThirdLine";
const myStr = "FirstLine\n\t\\SecondLine\nThirdLine";
```

View File

@ -14,7 +14,7 @@ Quando definisci una stringa devi cominciare e finire con una virgoletta singola
In JavaScript, puoi fare l'<dfn>escape</dfn> di una virgoletta per distinguerla da quella usata per terminare la stringa posizionando una <dfn>barra rovesciata</dfn> (`\`) davanti alla virgoletta.
```js
var sampleStr = "Alan said, \"Peter is learning JavaScript\".";
const sampleStr = "Alan said, \"Peter is learning JavaScript\".";
```
Questo segnala a JavaScript che la virgoletta seguente non è la fine della stringa, ma dovrebbe invece apparire dentro la stringa. Quindi se dovessi farla visualizzare nella console, otterresti:
@ -62,11 +62,11 @@ assert(/I am a "double quoted" string inside "double quotes(\."|"\.)$/.test(mySt
## --seed-contents--
```js
var myStr = ""; // Change this line
const myStr = ""; // Change this line
```
# --solutions--
```js
var myStr = "I am a \"double quoted\" string inside \"double quotes\".";
const myStr = "I am a \"double quoted\" string inside \"double quotes\".";
```

View File

@ -8,32 +8,30 @@ dashedName: explore-differences-between-the-var-and-let-keywords
# --description--
Uno dei maggiori problemi quando si dichiarano delle variabili con la parola chiave `var` è che è possibile sovrascrivere le dichiarazioni delle variabili senza errori.
Uno dei maggiori problemi quando si dichiarano delle variabili con la parola chiave `var` è che è possibile sovrascrivere facilmente le dichiarazioni delle variabili:
```js
var camper = 'James';
var camper = 'David';
var camper = "James";
var camper = "David";
console.log(camper);
```
Qui la console mostrerà la stringa `David`.
Nel codice qui sopra, la variabile `camper` è originariamente dichiarata come `James` per poi essere sovrascritta con `David`. La console poi mostra la stringa `David`.
Come puoi vedere nel codice qui sopra, la variabile `camper` è originariamente dichiarata come `James` per poi essere sovrascritta con `David`. In una piccola applicazione si potrebbe non incorrere in questo tipo di problema, ma quando il codice diventa più grande, potresti accidentalmente sovrascrivere una variabile che non hai intenzione di sovrascrivere. Poiché questo comportamento non lancia un errore, la ricerca e la correzione di bug diventa più difficile.
Una nuova parola chiave, chiamata `let`, è stata introdotta in ES6 per risolvere questo potenziale problema con la parola chiave `var`. Se dovessi sostituire `var` con `let` nelle dichiarazioni delle variabili nel codice sopra, il risultato sarebbe un errore.
In una piccola applicazione, potresti non incorrere in questo tipo di problema. Ma man mano che il tuo codebase diventa più grande potresti accidentalmente sovrascrivere una variabile che non intendevi sovrascrivere. Poiché questo comportamento non da errore, cercare e sistemare bug diventa più difficile.
Una parola chiave chiamata `let` è stata introdotta in ES6, un aggiornamento importante a JavaScript, per risolvere questo potenziale problema con la parola chiave `var`. Imparerai altre caratteristiche di ES6 in sfide future.
Se sostituisci `var` con `let` nel codice qua sopra, risulta in un errore:
```js
let camper = 'James';
let camper = 'David';
let camper = "James";
let camper = "David";
```
Questo errore può essere visto nella console del tuo browser. Quindi, a differenza di `var`, quando si utilizza `let`, una variabile con lo stesso nome può essere dichiarata solo una volta. Nota l'`"use strict"`. Questo abilita la Strict Mode (Modalità Rigorosa), che cattura gli errori di codifica comuni e le azioni "non sicure". Per esempio:
L'errore può essere visto nella console del browser.
```js
"use strict";
x = 3.14;
```
Questo mostrerà l'errore `x is not defined`.
Quindi a differenza di `var`, wuando usi `let`, una variabile con lo stesso nome può essere dichiarata una sola volta.
# --instructions--
@ -53,10 +51,10 @@ Aggiorna il codice in modo che utilizzi solo la parola chiave `let`.
assert(catName === 'Oliver');
```
`quote` dovrebbe essere uguale alla stringa `Oliver says Meow!`
`catSound` dovrebbe essere uguale alla stringa `Meow!`
```js
assert(quote === 'Oliver says Meow!');
assert(catSound === 'Meow!');
```
# --seed--
@ -64,28 +62,13 @@ assert(quote === 'Oliver says Meow!');
## --seed-contents--
```js
var catName;
var quote;
function catTalk() {
"use strict";
catName = "Oliver";
quote = catName + " says Meow!";
}
catTalk();
var catName = "Oliver";
var catSound = "Meow!";
```
# --solutions--
```js
let catName;
let quote;
function catTalk() {
'use strict';
catName = 'Oliver';
quote = catName + ' says Meow!';
}
catTalk();
let catName = "Oliver";
let catSound = "Meow!";
```

View File

@ -17,7 +17,7 @@ console.log("Alan Peter".length);
Il valore `10` sarà visualizzato nella console.
Ad esempio, se avessimo creato una variabile `var firstName = "Ada"`, potremmo scoprire quanto è lunga la stringa `Ada` utilizzando la proprietà `firstName.length`.
Ad esempio, se avessimo creato una variabile `const firstName = "Ada"`, potremmo scoprire quanto è lunga la stringa `Ada` utilizzando la proprietà `firstName.length`.
# --instructions--
@ -29,8 +29,8 @@ Non dovresti cambiare le dichiarazioni della variabile nella sezione `// Setup`.
```js
assert(
code.match(/var lastNameLength = 0;/) &&
code.match(/var lastName = "Lovelace";/)
code.match(/let lastNameLength = 0;/) &&
code.match(/const lastName = "Lovelace";/)
);
```
@ -52,18 +52,17 @@ assert(code.match(/=\s*lastName\.length/g) && !code.match(/lastName\s*=\s*8/));
```js
// Setup
var lastNameLength = 0;
var lastName = "Lovelace";
let lastNameLength = 0;
const lastName = "Lovelace";
// Only change code below this line
lastNameLength = lastName;
```
# --solutions--
```js
var lastNameLength = 0;
var lastName = "Lovelace";
let lastNameLength = 0;
const lastName = "Lovelace";
lastNameLength = lastName.length;
```

View File

@ -31,7 +31,7 @@ Imposta `remainder` pari al resto di `11` diviso per `3` utilizzando l'operatore
La variabile `remainder` dovrebbe essere inizializzata
```js
assert(/var\s+?remainder/.test(code));
assert(/(const|let|var)\s+?remainder/.test(code));
```
Il valore di `remainder` dovrebbe essere `2`
@ -57,13 +57,11 @@ assert(/\s+?remainder\s*?=\s*?.*%.*;?/.test(code));
## --seed-contents--
```js
// Only change code below this line
var remainder;
const remainder = 0;
```
# --solutions--
```js
var remainder = 11 % 3;
const remainder = 11 % 3;
```

View File

@ -11,13 +11,13 @@ dashedName: global-scope-and-functions
In JavaScript, lo <dfn>scope</dfn> (campo di applicazione o ambito di visibilità) si riferisce alla visibilità delle variabili. Le variabili che sono definite al di fuori del blocco di una funzione hanno un campo di applicazione <dfn>globale</dfn>. Questo significa che possono essere viste ovunque nel tuo codice JavaScript.
Le variabili che vengono dichiarate senza la parola chiave `var` vengono create automaticamente nell'ambito `global`. Questo può dare delle conseguenze indesiderate da un'altra parte nel tuo codice o quando si esegue nuovamente la funzione. Dovresti sempre dichiarare le tue variabili con `var`.
Le variabili che vengono dichiarate senza la parola chiave `let` o la parola chiave `const` vengono create automaticamente nell'ambito `global`. Questo può dare delle conseguenze indesiderate da un'altra parte nel tuo codice o quando si esegue nuovamente la funzione. Dovresti sempre dichiarare le tue variabili con `let` o `const`.
# --instructions--
Usando `var`, dichiara una variabile globale denominata `myGlobal` al di fuori di qualsiasi funzione. Inizializzala con un valore di `10`.
Usando `let` o `const`, dichiara una variabile globale denominata `myGlobal` al di fuori di qualsiasi funzione. Inizializzala con un valore di `10`.
All'interno della funzione `fun1`, assegna `5` a `oopsGlobal` ***senza*** utilizzare la parola chiave `var`.
All'interno della funzione `fun1`, assegna `5` a `oopsGlobal` ***senza*** utilizzare le parole chiave `let` o `const`.
# --hints--
@ -33,10 +33,10 @@ assert(typeof myGlobal != 'undefined');
assert(myGlobal === 10);
```
`myGlobal` dovrebbe essere dichiarata usando la parola chiave `var`
`myGlobal` dovrebbe essere dichiarata usando la parola chiave `let` o `const`
```js
assert(/var\s+myGlobal/.test(code));
assert(/(let|const)\s+myGlobal/.test(code));
```
`oopsGlobal` dovrebbe essere una variabile globale e avere un valore di `5`
@ -109,7 +109,7 @@ function fun2() {
# --solutions--
```js
var myGlobal = 10;
const myGlobal = 10;
function fun1() {
oopsGlobal = 5;

View File

@ -14,9 +14,10 @@ dashedName: global-vs--local-scope-in-functions
In questo esempio:
```js
var someVar = "Hat";
const someVar = "Hat";
function myFun() {
var someVar = "Head";
const someVar = "Head";
return someVar;
}
```
@ -53,13 +54,11 @@ assert(/return outerWear/.test(code));
```js
// Setup
var outerWear = "T-Shirt";
const outerWear = "T-Shirt";
function myOutfit() {
// Only change code below this line
// Only change code above this line
return outerWear;
}
@ -70,9 +69,9 @@ myOutfit();
# --solutions--
```js
var outerWear = "T-Shirt";
const outerWear = "T-Shirt";
function myOutfit() {
var outerWear = "sweater";
const outerWear = "sweater";
return outerWear;
}
```

View File

@ -90,7 +90,8 @@ assert(golfScore(5, 9) === 'Go Home!');
## --seed-contents--
```js
var names = ["Hole-in-one!", "Eagle", "Birdie", "Par", "Bogey", "Double Bogey", "Go Home!"];
const names = ["Hole-in-one!", "Eagle", "Birdie", "Par", "Bogey", "Double Bogey", "Go Home!"];
function golfScore(par, strokes) {
// Only change code below this line

View File

@ -39,7 +39,7 @@ Non dovresti utilizzare l'operatore di assegnazione.
```js
assert(
/var\s*myVar\s*=\s*87;\s*\/*.*\s*([+]{2}\s*myVar|myVar\s*[+]{2});/.test(code)
/let\s*myVar\s*=\s*87;\s*\/*.*\s*([+]{2}\s*myVar|myVar\s*[+]{2});/.test(code)
);
```
@ -52,7 +52,7 @@ assert(/[+]{2}\s*myVar|myVar\s*[+]{2}/.test(code));
Non dovresti cambiare il codice sopra il commento specificato.
```js
assert(/var myVar = 87;/.test(code));
assert(/let myVar = 87;/.test(code));
```
# --seed--
@ -66,7 +66,7 @@ assert(/var myVar = 87;/.test(code));
## --seed-contents--
```js
var myVar = 87;
let myVar = 87;
// Only change code below this line
myVar = myVar + 1;
@ -75,6 +75,6 @@ myVar = myVar + 1;
# --solutions--
```js
var myVar = 87;
let myVar = 87;
myVar++;
```

View File

@ -64,7 +64,7 @@ assert(testElse(10) === 'Bigger than 5');
Non dovresti modificare il codice sopra o sotto i commenti specificati.
```js
assert(/var result = "";/.test(code) && /return result;/.test(code));
assert(/let result = "";/.test(code) && /return result;/.test(code));
```
# --seed--
@ -73,7 +73,7 @@ assert(/var result = "";/.test(code) && /return result;/.test(code));
```js
function testElse(val) {
var result = "";
let result = "";
// Only change code below this line
if (val > 5) {
@ -95,7 +95,7 @@ testElse(4);
```js
function testElse(val) {
var result = "";
let result = "";
if(val > 5) {
result = "Bigger than 5";
} else {

View File

@ -14,13 +14,14 @@ I cicli for non devono necessariamente iterare un numero alla volta. Modificando
Inizieremo da `i = 0` e ripeteremo il ciclo finché `i < 10`. Incrementeremo `i` di 2 ad ogni ciclo con `i += 2`.
```js
var ourArray = [];
for (var i = 0; i < 10; i += 2) {
const ourArray = [];
for (let i = 0; i < 10; i += 2) {
ourArray.push(i);
}
```
`ourArray` ora conterrà `[0,2,4,6,8]`. Cambiamo la nostra `initialization` in modo da poter iterare sui numeri dispari.
`ourArray` ora conterrà `[0, 2, 4, 6, 8]`. Cambiamo la nostra `initialization` in modo da poter iterare sui numeri dispari.
# --instructions--
@ -34,7 +35,7 @@ Dovresti usare un ciclo `for`.
assert(/for\s*\([^)]+?\)/.test(code));
```
`myArray` dovrebbe essere uguale a `[1,3,5,7,9]`.
`myArray` dovrebbe essere uguale a `[1, 3, 5, 7, 9]`.
```js
assert.deepEqual(myArray, [1, 3, 5, 7, 9]);
@ -52,16 +53,17 @@ if(typeof myArray !== "undefined"){(function(){return myArray;})();}
```js
// Setup
var myArray = [];
const myArray = [];
// Only change code below this line
```
# --solutions--
```js
var myArray = [];
for (var i = 1; i < 10; i += 2) {
const myArray = [];
for (let i = 1; i < 10; i += 2) {
myArray.push(i);
}
```

View File

@ -12,8 +12,9 @@ dashedName: iterate-through-an-array-with-a-for-loop
Un compito comune in JavaScript è quello di iterare attraverso i contenuti di un array. Un modo per farlo è con un ciclo `for`. Questo codice visualizzerà ogni elemento dell'array `arr` nella console:
```js
var arr = [10, 9, 8, 7, 6];
for (var i = 0; i < arr.length; i++) {
const arr = [10, 9, 8, 7, 6];
for (let i = 0; i < arr.length; i++) {
console.log(arr[i]);
}
```
@ -62,18 +63,19 @@ assert(!__helpers.removeWhiteSpace(code).match(/total[=+-]0*[1-9]+/gm));
```js
// Setup
var myArr = [ 2, 3, 4, 5, 6];
const myArr = [2, 3, 4, 5, 6];
// Only change code below this line
```
# --solutions--
```js
var myArr = [ 2, 3, 4, 5, 6];
var total = 0;
const myArr = [2, 3, 4, 5, 6];
let total = 0;
for (var i = 0; i < myArr.length; i++) {
for (let i = 0; i < myArr.length; i++) {
total += myArr[i];
}
```

View File

@ -12,8 +12,9 @@ dashedName: iterate-with-javascript-do---while-loops
Il prossimo tipo di ciclo che vedremo si chiama `do...while`. Si chiama ciclo `do... while` perché prima eseguirà (`do`) un passaggio del codice all'interno del ciclo indipendentemente dalle condizioni, e poi continuerà ad eseguire il ciclo finché (`while`) la condizione specificata avrà valore `true`.
```js
var ourArray = [];
var i = 0;
const ourArray = [];
let i = 0;
do {
ourArray.push(i);
i++;
@ -23,8 +24,9 @@ do {
L'esempio sopra si comporta come altri tipi di cicli, e l'array risultante sarà `[0, 1, 2, 3, 4]`. Tuttavia, ciò che rende il `do...while` diverso da altri cicli è come si comporta quando la condizione fallisce al primo controllo. Vediamolo in azione: ecco un normale ciclo `while` che eseguirà il codice nel ciclo finché `i < 5`:
```js
var ourArray = [];
var i = 5;
const ourArray = [];
let i = 5;
while (i < 5) {
ourArray.push(i);
i++;
@ -34,8 +36,9 @@ while (i < 5) {
In questo esempio, inizializziamo il valore di `ourArray` a un array vuoto e il valore di `i` a 5. Quando eseguiamo il ciclo `while`, la condizione vale `false` perché `i` non è inferiore a 5, e in questo modo non eseguiremo il codice all'interno del ciclo. Il risultato è che `ourArray` finirà per non avere valori aggiunti, e sarà ancora simile a `[]` quando tutto il codice nell'esempio precedente sarà stato completato. Ora, dai un'occhiata a un ciclo `do...while`:
```js
var ourArray = [];
var i = 5;
const ourArray = [];
let i = 5;
do {
ourArray.push(i);
i++;
@ -80,8 +83,8 @@ if(typeof myArray !== "undefined"){(function(){return myArray;})();}
```js
// Setup
var myArray = [];
var i = 10;
const myArray = [];
let i = 10;
// Only change code below this line
while (i < 5) {
@ -93,8 +96,8 @@ while (i < 5) {
# --solutions--
```js
var myArray = [];
var i = 10;
const myArray = [];
let i = 10;
do {
myArray.push(i);
i++;

View File

@ -26,13 +26,14 @@ L'espressione finale è eseguita alla fine di ogni iterazione del ciclo, prima d
Nell'esempio seguente inizializziamo con `i = 0` e iteriamo finché la nostra condizione `i < 5` è vera. Incrementeremo `i` di `1` ad ogni iterazione del ciclo con `i++` come espressione finale.
```js
var ourArray = [];
for (var i = 0; i < 5; i++) {
const ourArray = [];
for (let i = 0; i < 5; i++) {
ourArray.push(i);
}
```
`ourArray` ha ora il valore `[0,1,2,3,4]`.
`ourArray` ha ora il valore `[0, 1, 2, 3, 4]`.
# --instructions--
@ -46,7 +47,7 @@ Dovresti usare un ciclo `for`.
assert(/for\s*\([^)]+?\)/.test(code));
```
`myArray` dovrebbe essere uguale a `[1,2,3,4,5]`.
`myArray` dovrebbe essere uguale a `[1, 2, 3, 4, 5]`.
```js
assert.deepEqual(myArray, [1, 2, 3, 4, 5]);
@ -64,16 +65,17 @@ if (typeof myArray !== "undefined"){(function(){return myArray;})();}
```js
// Setup
var myArray = [];
const myArray = [];
// Only change code below this line
```
# --solutions--
```js
var myArray = [];
for (var i = 1; i < 6; i++) {
const myArray = [];
for (let i = 1; i < 6; i++) {
myArray.push(i);
}
```

View File

@ -14,9 +14,10 @@ dashedName: iterate-with-javascript-while-loops
Il primo tipo di ciclo che vedremo è chiamato un ciclo `while` perché viene eseguito finché (while) una condizione specificata è vera e si arresta una volta che la condizione non è più vera.
```js
var ourArray = [];
var i = 0;
while(i < 5) {
const ourArray = [];
let i = 0;
while (i < 5) {
ourArray.push(i);
i++;
}
@ -38,7 +39,7 @@ Dovresti usare un ciclo `while`.
assert(code.match(/while/g));
```
`myArray` dovrebbe essere uguale a `[5,4,3,2,1,0]`.
`myArray` dovrebbe essere uguale a `[5, 4, 3, 2, 1, 0]`.
```js
assert.deepEqual(myArray, [5, 4, 3, 2, 1, 0]);
@ -56,17 +57,18 @@ if(typeof myArray !== "undefined"){(function(){return myArray;})();}
```js
// Setup
var myArray = [];
const myArray = [];
// Only change code below this line
```
# --solutions--
```js
var myArray = [];
var i = 5;
while(i >= 0) {
const myArray = [];
let i = 5;
while (i >= 0) {
myArray.push(i);
i--;
}

View File

@ -15,9 +15,10 @@ Ecco una funzione `myTest` con una variabile locale chiamata `loc`.
```js
function myTest() {
var loc = "foo";
const loc = "foo";
console.log(loc);
}
myTest();
console.log(loc);
```
@ -38,6 +39,7 @@ Il codice non dovrebbe contenere una variabile globale `myVar`.
function declared() {
myVar;
}
assert.throws(declared, ReferenceError);
```
@ -57,7 +59,6 @@ assert(
```js
function myLocalScope() {
// Only change code below this line
console.log('inside myLocalScope', myVar);
@ -73,9 +74,8 @@ console.log('outside myLocalScope', myVar);
```js
function myLocalScope() {
// Only change code below this line
var myVar;
let myVar;
console.log('inside myLocalScope', myVar);
}
myLocalScope();

View File

@ -16,8 +16,8 @@ Un altro modo per cambiare i dati in un array è con la funzione `.pop()`.
Qualsiasi tipo di elemento può essere estratto da un array - numeri, stringhe, anche array annidati.
```js
var threeArr = [1, 4, 6];
var oneDown = threeArr.pop();
const threeArr = [1, 4, 6];
const oneDown = threeArr.pop();
console.log(oneDown);
console.log(threeArr);
```
@ -26,7 +26,7 @@ Il primo `console.log` mostrerà il valore `6`e il secondo mostrerà il valore `
# --instructions--
Utilizza la funzione `.pop()` per rimuovere l'ultimo elemento da `myArray`, assegnando il valore estratto a `removedFromMyArray`.
Utilizza la funzione `.pop()` per rimuovere l'ultimo elemento da `myArray` e assegna il valore estratto a `removedFromMyArray`.
# --hints--
@ -69,22 +69,22 @@ assert(
## --after-user-code--
```js
(function(y, z){return 'myArray = ' + JSON.stringify(y) + ' & removedFromMyArray = ' + JSON.stringify(z);})(myArray, removedFromMyArray);
if (typeof removedFromMyArray !== 'undefined') (function(y, z){return 'myArray = ' + JSON.stringify(y) + ' & removedFromMyArray = ' + JSON.stringify(z);})(myArray, removedFromMyArray);
```
## --seed-contents--
```js
// Setup
var myArray = [["John", 23], ["cat", 2]];
const myArray = [["John", 23], ["cat", 2]];
// Only change code below this line
var removedFromMyArray;
```
# --solutions--
```js
var myArray = [["John", 23], ["cat", 2]];
var removedFromMyArray = myArray.pop();
const myArray = [["John", 23], ["cat", 2]];
const removedFromMyArray = myArray.pop();
```

View File

@ -16,10 +16,10 @@ Un modo semplice per aggiungere dei dati alla fine di un array è tramite la fun
Esempi:
```js
var arr1 = [1,2,3];
const arr1 = [1, 2, 3];
arr1.push(4);
var arr2 = ["Stimpson", "J", "cat"];
const arr2 = ["Stimpson", "J", "cat"];
arr2.push(["happy", "joy"]);
```
@ -64,14 +64,15 @@ assert(
```js
// Setup
var myArray = [["John", 23], ["cat", 2]];
const myArray = [["John", 23], ["cat", 2]];
// Only change code below this line
```
# --solutions--
```js
var myArray = [["John", 23], ["cat", 2]];
const myArray = [["John", 23], ["cat", 2]];
myArray.push(["dog",3]);
```

View File

@ -16,15 +16,15 @@ dashedName: manipulate-arrays-with-shift
Esempio:
```js
var ourArray = ["Stimpson", "J", ["cat"]];
var removedFromOurArray = ourArray.shift();
const ourArray = ["Stimpson", "J", ["cat"]];
const removedFromOurArray = ourArray.shift();
```
`removedFromOurArray` dovrebbe avere un valore stringa `Stimpson`e `ourArray` dovrebbe valere `["J", ["cat"]]`.
# --instructions--
Utilizza la funzione `.shift()` per rimuovere il primo elemento da `myArray`, assegnando il valore "spostato" a `removedFromMyArray`.
Utilizza la funzione `.shift()` per rimuovere il primo elemento da `myArray` e assegna il valore estratto a `removedFromMyArray`.
# --hints--
@ -65,24 +65,24 @@ assert(
## --after-user-code--
```js
(function(y, z){return 'myArray = ' + JSON.stringify(y) + ' & removedFromMyArray = ' + JSON.stringify(z);})(myArray, removedFromMyArray);
if (typeof removedFromMyArray !== 'undefined') (function(y, z){return 'myArray = ' + JSON.stringify(y) + ' & removedFromMyArray = ' + JSON.stringify(z);})(myArray, removedFromMyArray);
```
## --seed-contents--
```js
// Setup
var myArray = [["John", 23], ["dog", 3]];
const myArray = [["John", 23], ["dog", 3]];
// Only change code below this line
var removedFromMyArray;
```
# --solutions--
```js
var myArray = [["John", 23], ["dog", 3]];
const myArray = [["John", 23], ["dog", 3]];
// Only change code below this line
var removedFromMyArray = myArray.shift();
const removedFromMyArray = myArray.shift();
```

View File

@ -16,7 +16,7 @@ Non puoi solo fare uno `shift` di elementi dall'inizio di un array: puoi anche f
Esempio:
```js
var ourArray = ["Stimpson", "J", "cat"];
const ourArray = ["Stimpson", "J", "cat"];
ourArray.shift();
ourArray.unshift("Happy");
```
@ -25,7 +25,7 @@ Dopo lo `shift`, `ourArray` avrà il valore `["J", "cat"]`. Dopo l'`unshift`, `o
# --instructions--
Aggiungi `["Paul",35]` all'inizio della variabile `myArray` usando `unshift()`.
Aggiungi `["Paul", 35]` all'inizio della variabile `myArray` usando `unshift()`.
# --hints--
@ -63,16 +63,17 @@ assert(
```js
// Setup
var myArray = [["John", 23], ["dog", 3]];
const myArray = [["John", 23], ["dog", 3]];
myArray.shift();
// Only change code below this line
```
# --solutions--
```js
var myArray = [["John", 23], ["dog", 3]];
const myArray = [["John", 23], ["dog", 3]];
myArray.shift();
myArray.unshift(["Paul", 35]);
```

View File

@ -14,7 +14,7 @@ A volte potresti voler memorizzare i dati in una <dfn>struttura di dati</dfn> fl
Ecco un esempio di struttura di dati complessa:
```js
var ourMusic = [
const ourMusic = [
{
"artist": "Daft Punk",
"title": "Homework",
@ -135,7 +135,7 @@ myMusic.forEach(object => {
## --seed-contents--
```js
var myMusic = [
const myMusic = [
{
"artist": "Billy Joel",
"title": "Piano Man",
@ -153,7 +153,7 @@ var myMusic = [
# --solutions--
```js
var myMusic = [
const myMusic = [
{
"artist": "Billy Joel",
"title": "Piano Man",

View File

@ -9,12 +9,12 @@ dashedName: modify-array-data-with-indexes
# --description--
A differenza delle stringhe, gli elementi degli array sono <dfn>mutabili</dfn> e possono essere cambiati liberamente.
A differenza delle stringhe, gli elementi degli array sono <dfn>mutabili</dfn> e possono essere cambiati liberamente, anche se l'array è stato dichiarato con `const`.
**Esempio**
```js
var ourArray = [50,40,30];
const ourArray = [50, 40, 30];
ourArray[0] = 15;
```
@ -28,7 +28,7 @@ Modificare i dati memorizzati all'indice `0` di `myArray` a un valore di `45`.
# --hints--
`myArray` dovrebbe ora essere `[45,64,99]`.
`myArray` dovrebbe ora essere `[45, 64, 99]`.
```js
assert(
@ -73,14 +73,15 @@ if(typeof myArray !== "undefined"){(function(){return myArray;})();}
```js
// Setup
var myArray = [18,64,99];
const myArray = [18, 64, 99];
// Only change code below this line
```
# --solutions--
```js
var myArray = [18,64,99];
const myArray = [18, 64, 99];
myArray[0] = 45;
```

View File

@ -12,7 +12,7 @@ dashedName: multiple-identical-options-in-switch-statements
Se l'istruzione `break` viene omessa da un'istruzione `switch` e in particolare da un suo `case`, le istruzione `case` successive sono eseguite fino a quando non si incontra un `break`. Se hai diversi input con lo stesso output, potrai rappresentarli in un'istruzione `switch` come la seguente:
```js
var result = "";
let result = "";
switch(val) {
case 1:
case 2:
@ -109,7 +109,7 @@ assert(code.match(/case/g).length === 9);
```js
function sequentialSizes(val) {
var answer = "";
let answer = "";
// Only change code below this line
@ -125,7 +125,7 @@ sequentialSizes(1);
```js
function sequentialSizes(val) {
var answer = "";
let answer = "";
switch(val) {
case 1:

View File

@ -42,11 +42,11 @@ assert(/\*/.test(code));
## --seed-contents--
```js
var product = 2.0 * 0.0;
const product = 2.0 * 0.0;
```
# --solutions--
```js
var product = 2.0 * 2.5;
const product = 2.0 * 2.5;
```

View File

@ -16,7 +16,7 @@ JavaScript utilizza il simbolo `*` per la moltiplicazione di due numeri.
**Esempio**
```js
myVar = 13 * 13;
const myVar = 13 * 13;
```
`myVar` dovrebbe avere il valore `169`.
@ -50,11 +50,11 @@ assert(/\*/.test(code));
## --seed-contents--
```js
var product = 8 * 0;
const product = 8 * 0;
```
# --solutions--
```js
var product = 8 * 10;
const product = 8 * 10;
```

View File

@ -12,7 +12,7 @@ dashedName: nest-one-array-within-another-array
È anche possibile nidificare array all'interno di altri array, come nell'esempio:
```js
[["Bulls", 23], ["White Sox", 45]]
const teams = [["Bulls", 23], ["White Sox", 45]];
```
Questo viene anche chiamato un <dfn>array multidimensionale</dfn>.
@ -41,11 +41,11 @@ if(typeof myArray !== "undefined"){(function(){return myArray;})();}
```js
// Only change code below this line
var myArray = [];
const myArray = [];
```
# --solutions--
```js
var myArray = [[1,2,3]];
const myArray = [[1, 2, 3]];
```

View File

@ -12,11 +12,12 @@ dashedName: nesting-for-loops
Se disponi di un array multidimensionale, è possibile utilizzare la stessa logica del punto precedente per iterare sia attraverso l'array che attraverso i suoi sottoarray. Ecco un esempio:
```js
var arr = [
[1,2], [3,4], [5,6]
const arr = [
[1, 2], [3, 4], [5, 6]
];
for (var i=0; i < arr.length; i++) {
for (var j=0; j < arr[i].length; j++) {
for (let i = 0; i < arr.length; i++) {
for (let j = 0; j < arr[i].length; j++) {
console.log(arr[i][j]);
}
}
@ -30,13 +31,13 @@ Modifica la funzione `multiplyAll` in modo che restituisca il prodotto di tutti
# --hints--
`multiplyAll([[1],[2],[3]])` dovrebbe restituire `6`
`multiplyAll([[1], [2], [3]])` dovrebbe restituire `6`
```js
assert(multiplyAll([[1], [2], [3]]) === 6);
```
`multiplyAll([[1,2],[3,4],[5,6,7]])` dovrebbe restituire `5040`
`multiplyAll([[1, 2], [3, 4], [5, 6, 7]])` dovrebbe restituire `5040`
```js
assert(
@ -48,7 +49,7 @@ assert(
);
```
`multiplyAll([[5,1],[0.2, 4, 0.5],[3, 9]])` dovrebbe restituire `54`
`multiplyAll([[5, 1], [0.2, 4, 0.5], [3, 9]])` dovrebbe restituire `54`
```js
assert(
@ -66,28 +67,26 @@ assert(
```js
function multiplyAll(arr) {
var product = 1;
let product = 1;
// Only change code below this line
// Only change code above this line
return product;
}
multiplyAll([[1,2],[3,4],[5,6,7]]);
multiplyAll([[1, 2], [3, 4], [5, 6, 7]]);
```
# --solutions--
```js
function multiplyAll(arr) {
var product = 1;
for (var i = 0; i < arr.length; i++) {
for (var j = 0; j < arr[i].length; j++) {
let product = 1;
for (let i = 0; i < arr.length; i++) {
for (let j = 0; j < arr[i].length; j++) {
product *= arr[i][j];
}
}
return product;
}
multiplyAll([[1,2],[3,4],[5,6,7]]);
```

View File

@ -68,34 +68,33 @@ assert(lookUpProfile('Akira', 'address') === 'No such property');
```js
// Setup
var contacts = [
{
"firstName": "Akira",
"lastName": "Laine",
"number": "0543236543",
"likes": ["Pizza", "Coding", "Brownie Points"]
},
{
"firstName": "Harry",
"lastName": "Potter",
"number": "0994372684",
"likes": ["Hogwarts", "Magic", "Hagrid"]
},
{
"firstName": "Sherlock",
"lastName": "Holmes",
"number": "0487345643",
"likes": ["Intriguing Cases", "Violin"]
},
{
"firstName": "Kristian",
"lastName": "Vos",
"number": "unknown",
"likes": ["JavaScript", "Gaming", "Foxes"]
}
const contacts = [
{
firstName: "Akira",
lastName: "Laine",
number: "0543236543",
likes: ["Pizza", "Coding", "Brownie Points"],
},
{
firstName: "Harry",
lastName: "Potter",
number: "0994372684",
likes: ["Hogwarts", "Magic", "Hagrid"],
},
{
firstName: "Sherlock",
lastName: "Holmes",
number: "0487345643",
likes: ["Intriguing Cases", "Violin"],
},
{
firstName: "Kristian",
lastName: "Vos",
number: "unknown",
likes: ["JavaScript", "Gaming", "Foxes"],
},
];
function lookUpProfile(name, prop) {
// Only change code below this line
@ -108,44 +107,38 @@ lookUpProfile("Akira", "likes");
# --solutions--
```js
var contacts = [
{
"firstName": "Akira",
"lastName": "Laine",
"number": "0543236543",
"likes": ["Pizza", "Coding", "Brownie Points"]
},
{
"firstName": "Harry",
"lastName": "Potter",
"number": "0994372684",
"likes": ["Hogwarts", "Magic", "Hagrid"]
},
{
"firstName": "Sherlock",
"lastName": "Holmes",
"number": "0487345643",
"likes": ["Intriguing Cases", "Violin"]
},
{
"firstName": "Kristian",
"lastName": "Vos",
"number": "unknown",
"likes": ["JavaScript", "Gaming", "Foxes"]
},
const contacts = [
{
firstName: "Akira",
lastName: "Laine",
number: "0543236543",
likes: ["Pizza", "Coding", "Brownie Points"],
},
{
firstName: "Harry",
lastName: "Potter",
number: "0994372684",
likes: ["Hogwarts", "Magic", "Hagrid"],
},
{
firstName: "Sherlock",
lastName: "Holmes",
number: "0487345643",
likes: ["Intriguing Cases", "Violin"],
},
{
firstName: "Kristian",
lastName: "Vos",
number: "unknown",
likes: ["JavaScript", "Gaming", "Foxes"],
},
];
//Write your function in between these comments
function lookUpProfile(name, prop){
for(var i in contacts){
if(contacts[i].firstName === name) {
return contacts[i][prop] || "No such property";
}
function lookUpProfile(name, prop) {
for (let i in contacts) {
if (contacts[i].firstName === name) {
return contacts[i][prop] || "No such property";
}
return "No such contact";
}
return "No such contact";
}
//Write your function in between these comments
lookUpProfile("Akira", "likes");
```

View File

@ -12,21 +12,21 @@ dashedName: quoting-strings-with-single-quotes
I valori <dfn>Stringa</dfn> in JavaScript possono essere scritti con virgolette singole o doppie, purché si inizi e si termini con lo stesso tipo di virgolette. A differenza di alcuni altri linguaggi di programmazione, le virgolette singole e doppie funzionano allo stesso modo in JavaScript.
```js
doubleQuoteStr = "This is a string";
singleQuoteStr = 'This is also a string';
const doubleQuoteStr = "This is a string";
const singleQuoteStr = 'This is also a string';
```
Il motivo per cui potresti voler usare un tipo di virgolette piuttosto dell'altro è se volessi usare entrambi in una stringa. Questo potrebbe accadere volendo salvare una conversazione in una stringa e avendo la conversazione tra virgolette. Un altro uso sarebbe salvare un tag `<a>` con vari attributi tra virgolette, tutto all'interno di una stringa.
```js
conversation = 'Finn exclaims to Jake, "Algebraic!"';
const conversation = 'Finn exclaims to Jake, "Algebraic!"';
```
Tuttavia, questo diventa un problema se è necessario utilizzare le virgolette più esterne al suo interno. Ricorda, una stringa ha lo stesso tipo di virgolette all'inizio e alla fine. Ma se hai la stessa virgoletta da qualche parte nel mezzo, la stringa si fermerà anzitempo e lancerà un errore.
```js
goodStr = 'Jake asks Finn, "Hey, let\'s go on an adventure?"';
badStr = 'Finn responds, "Let's go!"';
const goodStr = 'Jake asks Finn, "Hey, let\'s go on an adventure?"';
const badStr = 'Finn responds, "Let's go!"';
```
Qui `badStr` genererà un errore.
@ -71,11 +71,11 @@ assert(code.match(/"/g).length === 4 && code.match(/'/g).length === 2);
## --seed-contents--
```js
var myStr = "<a href=\"http://www.example.com\" target=\"_blank\">Link</a>";
const myStr = "<a href=\"http://www.example.com\" target=\"_blank\">Link</a>";
```
# --solutions--
```js
var myStr = '<a href="http://www.example.com" target="_blank">Link</a>';
const myStr = '<a href="http://www.example.com" target="_blank">Link</a>';
```

View File

@ -115,7 +115,7 @@ const _recordCollection = {
```js
// Setup
var recordCollection = {
const recordCollection = {
2548: {
albumTitle: 'Slippery When Wet',
artist: 'Bon Jovi',
@ -146,7 +146,7 @@ updateRecords(recordCollection, 5439, 'artist', 'ABBA');
# --solutions--
```js
var recordCollection = {
const recordCollection = {
2548: {
albumTitle: 'Slippery When Wet',
artist: 'Bon Jovi',

View File

@ -14,9 +14,9 @@ La ricorsione è il concetto che una funzione può essere espressa in termini di
```js
function multiply(arr, n) {
var product = 1;
for (var i = 0; i < n; i++) {
product *= arr[i];
let product = 1;
for (let i = 0; i < n; i++) {
product *= arr[i];
}
return product;
}

View File

@ -108,7 +108,7 @@ assert(chainToSwitch(156) === '');
```js
function chainToSwitch(val) {
var answer = "";
let answer = "";
// Only change code below this line
if (val === "bob") {
@ -134,7 +134,7 @@ chainToSwitch(7);
```js
function chainToSwitch(val) {
var answer = "";
let answer = "";
switch(val) {
case "bob":

View File

@ -17,7 +17,8 @@ Possiamo passare dei valori a una funzione con gli <dfn>argomenti</dfn>. È poss
function plusThree(num) {
return num + 3;
}
var answer = plusThree(5);
const answer = plusThree(5);
```
`answer` ha il valore `8`.

View File

@ -33,43 +33,43 @@ Ricorda che [`undefined` è una parola chiave](https://www.freecodecamp.org/lear
# --hints--
`abTest(2,2)` dovrebbe restituire un numero
`abTest(2, 2)` dovrebbe restituire un numero
```js
assert(typeof abTest(2, 2) === 'number');
```
`abTest(2,2)` dovrebbe restituire `8`
`abTest(2, 2)` dovrebbe restituire `8`
```js
assert(abTest(2, 2) === 8);
```
`abTest(-2,2)` dovrebbe restituire `undefined`
`abTest(-2, 2)` dovrebbe restituire `undefined`
```js
assert(abTest(-2, 2) === undefined);
```
`abTest(2,-2)` dovrebbe restituire `undefined`
`abTest(2, -2)` dovrebbe restituire `undefined`
```js
assert(abTest(2, -2) === undefined);
```
`abTest(2,8)` dovrebbe restituire `18`
`abTest(2, 8)` dovrebbe restituire `18`
```js
assert(abTest(2, 8) === 18);
```
`abTest(3,3)` dovrebbe restituire `12`
`abTest(3, 3)` dovrebbe restituire `12`
```js
assert(abTest(3, 3) === 12);
```
`abTest(0,0)` dovrebbe restituire `0`
`abTest(0, 0)` dovrebbe restituire `0`
```js
assert(abTest(0, 0) === 0);

View File

@ -14,7 +14,7 @@ dashedName: returning-boolean-values-from-functions
A volte le persone usano un'istruzione `if/else` per fare un confronto, in questo modo:
```js
function isEqual(a,b) {
function isEqual(a, b) {
if (a === b) {
return true;
} else {
@ -26,7 +26,7 @@ function isEqual(a,b) {
Ma c'è un modo migliore per farlo. Dal momento che `===` restituisce `true` o `false`, possiamo restituire il risultato del confronto:
```js
function isEqual(a,b) {
function isEqual(a, b) {
return a === b;
}
```
@ -37,13 +37,13 @@ Correggi la funzione `isLess` per rimuovere le istruzioni `if/else`.
# --hints--
`isLess(10,15)` dovrebbe restituire `true`
`isLess(10, 15)` dovrebbe restituire `true`
```js
assert(isLess(10, 15) === true);
```
`isLess(15,10)` dovrebbe restituire `false`
`isLess(15, 10)` dovrebbe restituire `false`
```js
assert(isLess(15, 10) === false);

View File

@ -78,7 +78,7 @@ assert(code.match(/break/g).length > 2);
```js
function caseInSwitch(val) {
var answer = "";
let answer = "";
// Only change code below this line
@ -94,7 +94,7 @@ caseInSwitch(1);
```js
function caseInSwitch(val) {
var answer = "";
let answer = "";
switch(val) {
case 1:

View File

@ -81,13 +81,13 @@ var hasNumber = false;
## --seed-contents--
```js
var myList = [];
const myList = [];
```
# --solutions--
```js
var myList = [
const myList = [
["Candy", 10],
["Potatoes", 12],
["Eggs", 12],

View File

@ -93,12 +93,10 @@ function nextInLine(arr, item) {
return item;
// Only change code above this line
}
// Setup
var testArr = [1,2,3,4,5];
const testArr = [1, 2, 3, 4, 5];
// Display code
console.log("Before: " + JSON.stringify(testArr));
@ -109,7 +107,7 @@ console.log("After: " + JSON.stringify(testArr));
# --solutions--
```js
var testArr = [ 1,2,3,4,5];
const testArr = [1, 2, 3, 4, 5];
function nextInLine(arr, item) {
arr.push(item);

View File

@ -14,7 +14,7 @@ Con le variabili `array` di JavaScript, possiamo memorizzare diversi dati in un
La dichiarazione di un array inizia con una parentesi quadra di apertura, e termina con una parentesi quadra di chiusura, con gli elementi separati da virgole, in questo modo:
```js
var sandwich = ["peanut butter", "jelly", "bread"]
const sandwich = ["peanut butter", "jelly", "bread"];
```
# --instructions--
@ -53,11 +53,11 @@ assert(typeof myArray[1] !== 'undefined' && typeof myArray[1] == 'number');
```js
// Only change code below this line
var myArray = [];
const myArray = [];
```
# --solutions--
```js
var myArray = ["The Answer", 42];
const myArray = ["The Answer", 42];
```

View File

@ -16,7 +16,7 @@ JavaScript utilizza il simbolo `-` per la sottrazione.
**Esempio**
```js
myVar = 12 - 6;
const myVar = 12 - 6;
```
`myVar` avrà il valore `6`.
@ -49,11 +49,11 @@ assert(/difference=45-33;?/.test(__helpers.removeWhiteSpace(code)));
## --seed-contents--
```js
var difference = 45 - 0;
const difference = 45 - 0;
```
# --solutions--
```js
var difference = 45 - 33;
const difference = 45 - 33;
```

View File

@ -13,10 +13,11 @@ A volte è utile verificare se la proprietà di un dato oggetto esiste o meno. P
**Esempio**
```js
var myObj = {
const myObj = {
top: "hat",
bottom: "pants"
};
myObj.hasOwnProperty("top");
myObj.hasOwnProperty("middle");
```

View File

@ -14,14 +14,14 @@ In JavaScript, le stringhe (`String`) sono <dfn>immutabili</dfn>, il che signifi
Ad esempio, il codice seguente:
```js
var myStr = "Bob";
let myStr = "Bob";
myStr[0] = "J";
```
non può modificare il valore di `myStr` in `Job`, poiché il contenuto di `myStr` non può essere modificato. Tieni presente che questo *non* significa che `myStr` non può essere modificato, ma solo che i singoli caratteri di una <dfn>stringa letterale</dfn> non possono essere cambiati. L'unico modo per modificare `myStr` è di assegnargli una nuova stringa, in questo modo:
```js
var myStr = "Bob";
let myStr = "Bob";
myStr = "Job";
```
@ -55,7 +55,7 @@ assert(/myStr = "Jello World"/.test(code));
```js
// Setup
var myStr = "Jello World";
let myStr = "Jello World";
// Only change code below this line
myStr[0] = "H"; // Change this line
@ -65,6 +65,6 @@ myStr[0] = "H"; // Change this line
# --solutions--
```js
var myStr = "Jello World";
let myStr = "Jello World";
myStr = "Hello World";
```

View File

@ -43,7 +43,6 @@ welcomeToBooleans();
```js
function welcomeToBooleans() {
// Only change code below this line
return false; // Change this line

View File

@ -14,10 +14,12 @@ Una funzione può includere l'istruzione `return` ma questa non deve essere nece
**Esempio**
```js
var sum = 0;
let sum = 0;
function addSum(num) {
sum = sum + num;
}
addSum(3);
```
@ -61,7 +63,7 @@ assert(
```js
// Setup
var sum = 0;
let sum = 0;
function addThree() {
sum = sum + 3;
@ -79,7 +81,7 @@ addFive();
# --solutions--
```js
var sum = 0;
let sum = 0;
function addThree() {
sum = sum + 3;

View File

@ -14,7 +14,7 @@ Dopo aver creato un oggetto JavaScript, è possibile aggiornare le sue propriet
Ad esempio, diamo un'occhiata a `ourDog`:
```js
var ourDog = {
const ourDog = {
"name": "Camper",
"legs": 4,
"tails": 1,
@ -54,7 +54,7 @@ assert(/"name": "Coder"/.test(code));
```js
// Setup
var myDog = {
const myDog = {
"name": "Coder",
"legs": 4,
"tails": 1,
@ -62,12 +62,13 @@ var myDog = {
};
// Only change code below this line
```
# --solutions--
```js
var myDog = {
const myDog = {
"name": "Coder",
"legs": 4,
"tails": 1,

View File

@ -13,13 +13,13 @@ dashedName: use-bracket-notation-to-find-the-first-character-in-a-string
La maggior parte dei moderni linguaggi di programmazione, come JavaScript, non inizia a contare da 1 come gli esseri umani. Loro iniziano dallo 0. Questo è indicato come indicizzazione <dfn>Zero-based</dfn>.
Ad esempio, il carattere all'indice 0 nella parola `Charles` è `C`. Quindi, se `var firstName = "Charles"`, è possibile ottenere il valore della prima lettera della stringa utilizzando `firstName[0]`.
Ad esempio, il carattere all'indice 0 nella parola `Charles` è `C`. Quindi, se `const firstName = "Charles"`, è possibile ottenere il valore della prima lettera della stringa utilizzando `firstName[0]`.
Esempio:
```js
var firstName = "Charles";
var firstLetter = firstName[0];
const firstName = "Charles";
const firstLetter = firstName[0];
```
`firstLetter` dovrebbe avere un valore stringa `C`.
@ -56,8 +56,8 @@ assert(code.match(/firstLetterOfLastName\s*?=\s*?lastName\[.*?\]/));
```js
// Setup
var firstLetterOfLastName = "";
var lastName = "Lovelace";
let firstLetterOfLastName = "";
const lastName = "Lovelace";
// Only change code below this line
firstLetterOfLastName = lastName; // Change this line
@ -66,8 +66,8 @@ firstLetterOfLastName = lastName; // Change this line
# --solutions--
```js
var firstLetterOfLastName = "";
var lastName = "Lovelace";
let firstLetterOfLastName = "";
const lastName = "Lovelace";
// Only change code below this line
firstLetterOfLastName = lastName[0];

View File

@ -11,13 +11,13 @@ dashedName: use-bracket-notation-to-find-the-last-character-in-a-string
Al fine di ottenere l'ultima lettera di una stringa, è possibile sottrarre uno dalla lunghezza della stringa.
Per esempio, se `var firstName = "Ada"`, puoi ottenere il valore dell'ultima lettera della stringa usando `firstName[firstName.length - 1]`.
Per esempio, se `const firstName = "Ada"`, puoi ottenere il valore dell'ultima lettera della stringa usando `firstName[firstName.length - 1]`.
Esempio:
```js
var firstName = "Ada";
var lastLetter = firstName[firstName.length - 1];
const firstName = "Ada";
const lastLetter = firstName[firstName.length - 1];
```
`lastLetter` dovrebbe avere un valore stringa `a`.
@ -54,15 +54,15 @@ assert(code.match(/\.length/g).length > 0);
```js
// Setup
var lastName = "Lovelace";
const lastName = "Lovelace";
// Only change code below this line
var lastLetterOfLastName = lastName; // Change this line
const lastLetterOfLastName = lastName; // Change this line
```
# --solutions--
```js
var lastName = "Lovelace";
var lastLetterOfLastName = lastName[lastName.length - 1];
const lastName = "Lovelace";
const lastLetterOfLastName = lastName[lastName.length - 1];
```

View File

@ -16,8 +16,8 @@ Ricorda che i computer iniziano a contare da `0`, quindi il primo carattere è i
Esempio:
```js
var firstName = "Ada";
var secondLetterOfFirstName = firstName[1];
const firstName = "Ada";
const secondLetterOfFirstName = firstName[1];
```
`secondLetterOfFirstName` dovrebbe acere un valore stringa `d`.
@ -54,15 +54,15 @@ assert(code.match(/thirdLetterOfLastName\s*?=\s*?lastName\[.*?\]/));
```js
// Setup
var lastName = "Lovelace";
const lastName = "Lovelace";
// Only change code below this line
var thirdLetterOfLastName = lastName; // Change this line
const thirdLetterOfLastName = lastName; // Change this line
```
# --solutions--
```js
var lastName = "Lovelace";
var thirdLetterOfLastName = lastName[2];
const lastName = "Lovelace";
const thirdLetterOfLastName = lastName[2];
```

View File

@ -11,13 +11,13 @@ dashedName: use-bracket-notation-to-find-the-nth-to-last-character-in-a-string
È possibile utilizzare lo stesso principio che abbiamo appena usato per recuperare l'ultimo carattere in una stringa per recuperare il carattere n-ultimo dalla fine.
Ad esempio, puoi ottenere il valore della terzultima lettera della stringa `var firstName = "Augusta"` usando `firstName[firstName. lunghezza - 3]`
Ad esempio, puoi ottenere il valore della terzultima lettera della stringa `const firstName = "Augusta"` usando `firstName[firstName.length - 3]`
Esempio:
```js
var firstName = "Augusta";
var thirdToLastLetter = firstName[firstName.length - 3];
const firstName = "Augusta";
const thirdToLastLetter = firstName[firstName.length - 3];
```
`thirdToLastLetter` dovrebbe avere un valore stringa `s`.
@ -54,15 +54,15 @@ assert(code.match(/\.length/g).length > 0);
```js
// Setup
var lastName = "Lovelace";
const lastName = "Lovelace";
// Only change code below this line
var secondToLastLetterOfLastName = lastName; // Change this line
const secondToLastLetterOfLastName = lastName; // Change this line
```
# --solutions--
```js
var lastName = "Lovelace";
var secondToLastLetterOfLastName = lastName[lastName.length - 2];
const lastName = "Lovelace";
const secondToLastLetterOfLastName = lastName[lastName.length - 2];
```

View File

@ -9,7 +9,7 @@ dashedName: use-conditional-logic-with-if-statements
# --description--
Le istruzioni `If` sono usate nel codice per prendere decisioni. La parola chiave `if` dice a JavaScript di eseguire il codice nelle parentesi graffe in determinate condizioni, definite nelle parentesi tonde. Queste condizioni sono note come condizioni `Boolean` e possono essere solo `true` o `false`.
Le istruzioni `if` sono usate nel codice per prendere decisioni. La parola chiave `if` dice a JavaScript di eseguire il codice nelle parentesi graffe in determinate condizioni, definite nelle parentesi tonde. Queste condizioni sono note come condizioni `Boolean` e possono essere solo `true` o `false`.
Quando la condizione valuta un `true`, il programma esegue la dichiarazione all'interno delle parentesi graffe. Quando la condizione booleana valuta un `false`, la dichiarazione all'interno delle parentesi graffe non sarà eseguita.
@ -22,10 +22,11 @@ Quando la condizione valuta un `true`, il programma esegue la dichiarazione all'
```js
function test (myCondition) {
if (myCondition) {
return "It was true";
return "It was true";
}
return "It was false";
}
test(true);
test(false);
```

View File

@ -73,7 +73,7 @@ function rangeOfNumbers(startNum, endNum) {
if (endNum - startNum === 0) {
return [startNum];
} else {
var numbers = rangeOfNumbers(startNum, endNum - 1);
const numbers = rangeOfNumbers(startNum, endNum - 1);
numbers.push(endNum);
return numbers;
}

View File

@ -20,7 +20,7 @@ parseInt(string, radix);
Ecco un esempio:
```js
var a = parseInt("11", 2);
const a = parseInt("11", 2);
```
La variabile radix dice che `11` è nel sistema binario, o in base 2. Questo esempio converte la stringa `11` in un intero `3`.

View File

@ -12,7 +12,7 @@ dashedName: use-the-parseint-function
La funzione `parseInt()` analizza una stringa e restituisce un numero intero. Ecco un esempio:
```js
var a = parseInt("007");
const a = parseInt("007");
```
La funzione di cui sopra converte la stringa `007` nell'intero `7`. Se il primo carattere della stringa non può essere convertito in un numero, restituisce `NaN`.

View File

@ -14,7 +14,7 @@ Gli oggetti possono essere pensati come una memorizzazione di coppie chiave / va
Ecco l'esempio di una semplice ricerca in un alfabeto inverso:
```js
var alpha = {
const alpha = {
1:"Z",
2:"Y",
3:"X",
@ -24,10 +24,11 @@ var alpha = {
25:"B",
26:"A"
};
alpha[2];
alpha[24];
var value = 2;
const value = 2;
alpha[value];
```
@ -102,7 +103,7 @@ assert(
```js
// Setup
function phoneticLookup(val) {
var result = "";
let result = "";
// Only change code below this line
switch(val) {
@ -136,9 +137,9 @@ phoneticLookup("charlie");
```js
function phoneticLookup(val) {
var result = "";
let result = "";
var lookup = {
const lookup = {
alpha: "Adams",
bravo: "Boston",
charlie: "Chicago",

View File

@ -16,7 +16,7 @@ In un gioco "Mad Libs" ti vengono fornite frasi con alcune parole mancanti, come
Considera questa frase: It was really **\_\_\_\_**, and we **\_\_\_\_** ourselves **\_\_\_\_**. Questa frase ha tre parti mancanti - un aggettivo, un verbo e un avverbio, e possiamo aggiungere parole di nostra scelta per completarla. Possiamo quindi assegnare la frase completata a una variabile come segue:
```js
var sentence = "It was really " + "hot" + ", and we " + "laughed" + " ourselves " + "silly" + ".";
const sentence = "It was really " + "hot" + ", and we " + "laughed" + " ourselves " + "silly" + ".";
```
# --instructions--
@ -84,24 +84,24 @@ const removeAssignments = str => str
## --seed-contents--
```js
var myNoun = "dog";
var myAdjective = "big";
var myVerb = "ran";
var myAdverb = "quickly";
const myNoun = "dog";
const myAdjective = "big";
const myVerb = "ran";
const myAdverb = "quickly";
// Only change code below this line
var wordBlanks = ""; // Change this line
const wordBlanks = ""; // Change this line
// Only change code above this line
```
# --solutions--
```js
var myNoun = "dog";
var myAdjective = "big";
var myVerb = "ran";
var myAdverb = "quickly";
const myNoun = "dog";
const myAdjective = "big";
const myVerb = "ran";
const myAdverb = "quickly";
var wordBlanks = "Once there was a " + myNoun + " which was very " + myAdjective + ". ";
let wordBlanks = "Once there was a " + myNoun + " which was very " + myAdjective + ". ";
wordBlanks += "It " + myVerb + " " + myAdverb + " around the yard.";
```

View File

@ -8,11 +8,13 @@ dashedName: compare-scopes-of-the-var-and-let-keywords
# --description--
Se non hai familiarità con `let`, guarda [questa sfida](/italian/learn/javascript-algorithms-and-data-structures/basic-javascript/explore-differences-between-the-var-and-let-keywords).
Quando si dichiara una variabile con la parola chiave `var`, essa viene dichiarata globalmente, o localmente se dichiarata all'interno di una funzione.
La parola chiave `let` si comporta allo stesso modo, ma con alcune funzioni extra. Quando si dichiara una variabile con la parola chiave `let` all'interno di un blocco, di una dichiarazione o di un'espressione, il suo ambito di applicazione è limitato a tale blocco, dichiarazione o espressione.
Ad esempio:
Per esempio:
```js
var numArray = [];

View File

@ -8,6 +8,8 @@ dashedName: mutate-an-array-declared-with-const
# --description--
Se non hai familiarità con `const`, guarda [questa sfida](/italian/learn/javascript-algorithms-and-data-structures/basic-javascript/declare-a-read-only-variable-with-the-const-keyword).
La dichiarazione `const` ha molti casi di utilizzo nel JavaScript moderno.
Alcuni sviluppatori preferiscono assegnare tutte le loro variabili usando `const` come impostazione predefinita, a meno che non sappiano che dovranno riassegnare il valore. Solo in quel caso usano `let`.

View File

@ -13,7 +13,7 @@ La programmazione funzionale riguarda la creazione e l'utilizzo di funzioni non
L'ultima sfida ha introdotto il metodo `concat` come modo per combinare degli array in uno nuovo senza mutare gli array originali. Confronta `concat` con il metodo `push`. `push` aggiunge un elemento alla fine dello stesso array sul quale viene richiamato, mutando quello stesso array. Ecco un esempio:
```js
var arr = [1, 2, 3];
const arr = [1, 2, 3];
arr.push([4, 5, 6]);
```
@ -71,8 +71,9 @@ function nonMutatingPush(original, newItem) {
// Only change code above this line
}
var first = [1, 2, 3];
var second = [4, 5];
const first = [1, 2, 3];
const second = [4, 5];
nonMutatingPush(first, second);
```
@ -82,7 +83,6 @@ nonMutatingPush(first, second);
function nonMutatingPush(original, newItem) {
return original.concat(newItem);
}
var first = [1, 2, 3];
var second = [4, 5];
nonMutatingPush(first, second);
const first = [1, 2, 3];
const second = [4, 5];
```

View File

@ -77,7 +77,6 @@ function urlSlug(title) {
# --solutions--
```js
// Only change code below this line
function urlSlug(title) {
return title.trim().split(/\s+/).join("-").toLowerCase();
}

View File

@ -57,9 +57,9 @@ La tua funzione `incrementer` dovrebbe restituire un valore basato sul valore de
```js
// The global variable
var fixedValue = 4;
let fixedValue = 4;
function incrementer () {
function incrementer() {
// Only change code below this line
@ -70,7 +70,7 @@ function incrementer () {
# --solutions--
```js
var fixedValue = 4
let fixedValue = 4
function incrementer() {
return fixedValue + 1

View File

@ -13,8 +13,8 @@ Il metodo `join` viene utilizzato per unire gli elementi di un array per creare
Ecco un esempio:
```js
var arr = ["Hello", "World"];
var str = arr.join(" ");
const arr = ["Hello", "World"];
const str = arr.join(" ");
```
`str` conterrà la stringa `Hello World`.
@ -76,6 +76,7 @@ function sentensify(str) {
// Only change code above this line
}
sentensify("May-the-force-be-with-you");
```
@ -83,8 +84,6 @@ sentensify("May-the-force-be-with-you");
```js
function sentensify(str) {
// Only change code below this line
return str.split(/\W/).join(' ');
// Only change code above this line
}
```

View File

@ -60,8 +60,9 @@ function nonMutatingConcat(original, attach) {
// Only change code above this line
}
var first = [1, 2, 3];
var second = [4, 5];
const first = [1, 2, 3];
const second = [4, 5];
nonMutatingConcat(first, second);
```
@ -69,11 +70,8 @@ nonMutatingConcat(first, second);
```js
function nonMutatingConcat(original, attach) {
// Only change code below this line
return original.concat(attach);
// Only change code above this line
}
var first = [1, 2, 3];
var second = [4, 5];
nonMutatingConcat(first, second);
const first = [1, 2, 3];
const second = [4, 5];
```

View File

@ -38,17 +38,17 @@ assert(!code.match(/\.?[\s\S]*?map/g));
```js
// The global variable
var s = [23, 65, 98, 5];
const s = [23, 65, 98, 5];
Array.prototype.myMap = function(callback) {
var newArray = [];
const newArray = [];
// Only change code below this line
// Only change code above this line
return newArray;
};
var new_s = s.myMap(function(item) {
const new_s = s.myMap(function(item) {
return item * 2;
});
```
@ -56,20 +56,17 @@ var new_s = s.myMap(function(item) {
# --solutions--
```js
// the global Array
var s = [23, 65, 98, 5];
const s = [23, 65, 98, 5];
Array.prototype.myMap = function(callback) {
var newArray = [];
// Only change code below this line
for (var elem of this) {
const newArray = [];
for (const elem of this) {
newArray.push(callback(elem));
}
// Only change code above this line
return newArray;
};
var new_s = s.myMap(function(item) {
const new_s = s.myMap(function(item) {
return item * 2;
});
```

View File

@ -34,16 +34,16 @@ assert(!code.match(/\.?[\s\S]*?filter/g));
```js
// The global variable
var s = [23, 65, 98, 5];
const s = [23, 65, 98, 5];
Array.prototype.myFilter = function(callback) {
// Only change code below this line
var newArray = [];
const newArray = [];
// Only change code above this line
return newArray;
};
var new_s = s.myFilter(function(item) {
const new_s = s.myFilter(function(item) {
return item % 2 === 1;
});
```
@ -51,20 +51,17 @@ var new_s = s.myFilter(function(item) {
# --solutions--
```js
// the global Array
var s = [23, 65, 98, 5];
const s = [23, 65, 98, 5];
Array.prototype.myFilter = function(callback) {
var newArray = [];
// Only change code below this line
const newArray = [];
for (let i = 0; i < this.length; i++) {
if (callback(this[i])) newArray.push(this[i]);
}
// Only change code above this line
return newArray;
};
var new_s = s.myFilter(function(item) {
const new_s = s.myFilter(function(item) {
return item % 2 === 1;
});
```

View File

@ -35,7 +35,7 @@ curried(1)(2)
Questo sarà utile nel tuo programma se non sarai in grado di fornire tutti gli argomenti ad una funzione in una sola volta. Potrai salvare ogni chiamata di funzione in una variabile, che manterrà il riferimento alla funzione restituita, che prenderà l'argomento successivo quando sarà disponibile. Ecco un esempio usando la funzione curried dell'esempio visto sopra:
```js
var funcForY = curried(1);
const funcForY = curried(1);
console.log(funcForY(2)); // 3
```
@ -45,7 +45,8 @@ Allo stesso modo, <dfn>l'applicazione parziale</dfn> può essere descritta come
function impartial(x, y, z) {
return x + y + z;
}
var partialFn = impartial.bind(this, 1, 2);
const partialFn = impartial.bind(this, 1, 2);
partialFn(10); // 13
```
@ -90,6 +91,7 @@ function add(x) {
// Only change code above this line
}
add(10)(20)(30);
```

View File

@ -53,10 +53,10 @@ assert(__newValue === 5);
```js
// The global variable
var fixedValue = 4;
let fixedValue = 4;
// Only change code below this line
function incrementer () {
function incrementer() {
// Only change code above this line
@ -66,15 +66,9 @@ function incrementer () {
# --solutions--
```js
// The global variable
var fixedValue = 4;
let fixedValue = 4;
// Only change code below this line
function incrementer (fixedValue) {
function incrementer(fixedValue) {
return fixedValue + 1;
// Only change code above this line
}
```

View File

@ -10,7 +10,7 @@ dashedName: refactor-global-variables-out-of-functions
Finora abbiamo visto due principi distinti per la programmazione funzionale:
1) Non modificare una variabile o un oggetto - se necessario creare nuove variabili e oggetti e restituirli da una funzione. Suggerimento: usando qualcosa come `var newArr = arrVar`, dove `arrVar` è un array, creerai semplicemente un riferimento alla variabile esistente e non una copia. Quindi cambiando un valore in `newArr` cambierà anche il valore in `arrVar`.
1) Non modificare una variabile o un oggetto - se necessario creare nuove variabili e oggetti e restituirli da una funzione. Suggerimento: usando qualcosa come `const newArr = arrVar`, dove `arrVar` è un array, creerai semplicemente un riferimento alla variabile esistente e non una copia. Quindi cambiando un valore in `newArr` cambierà anche il valore in `arrVar`.
2) Dichiarare i parametri della funzione - qualsiasi calcolo all'interno di una funzione deve dipendere solo dagli argomenti passati alla funzione, e non da qualsiasi oggetto o variabile globale.
@ -86,7 +86,7 @@ assert(
```js
// The global variable
var bookList = ["The Hound of the Baskervilles", "On The Electrodynamics of Moving Bodies", "Philosophiæ Naturalis Principia Mathematica", "Disquisitiones Arithmeticae"];
const bookList = ["The Hound of the Baskervilles", "On The Electrodynamics of Moving Bodies", "Philosophiæ Naturalis Principia Mathematica", "Disquisitiones Arithmeticae"];
// Change code below this line
function add (bookName) {
@ -99,7 +99,7 @@ function add (bookName) {
// Change code below this line
function remove (bookName) {
var book_index = bookList.indexOf(bookName);
const book_index = bookList.indexOf(bookName);
if (book_index >= 0) {
bookList.splice(book_index, 1);
@ -109,9 +109,9 @@ function remove (bookName) {
}
}
var newBookList = add(bookList, 'A Brief History of Time');
var newerBookList = remove(bookList, 'On The Electrodynamics of Moving Bodies');
var newestBookList = remove(add(bookList, 'A Brief History of Time'), 'On The Electrodynamics of Moving Bodies');
const newBookList = add(bookList, 'A Brief History of Time');
const newerBookList = remove(bookList, 'On The Electrodynamics of Moving Bodies');
const newestBookList = remove(add(bookList, 'A Brief History of Time'), 'On The Electrodynamics of Moving Bodies');
console.log(bookList);
```
@ -120,13 +120,13 @@ console.log(bookList);
```js
// The global variable
var bookList = ["The Hound of the Baskervilles", "On The Electrodynamics of Moving Bodies", "Philosophiæ Naturalis Principia Mathematica", "Disquisitiones Arithmeticae"];
const bookList = ["The Hound of the Baskervilles", "On The Electrodynamics of Moving Bodies", "Philosophiæ Naturalis Principia Mathematica", "Disquisitiones Arithmeticae"];
function add (bookList, bookName) {
function add(bookList, bookName) {
return [...bookList, bookName];
}
function remove (bookList, bookName) {
function remove(bookList, bookName) {
const bookListCopy = [...bookList];
const bookNameIndex = bookList.indexOf(bookName);
if (bookNameIndex >= 0) {
@ -135,7 +135,7 @@ function remove (bookList, bookName) {
return bookListCopy;
}
var newBookList = add(bookList, 'A Brief History of Time');
var newerBookList = remove(bookList, 'On The Electrodynamics of Moving Bodies');
var newestBookList = remove(add(bookList, 'A Brief History of Time'), 'On The Electrodynamics of Moving Bodies');
const newBookList = add(bookList, 'A Brief History of Time');
const newerBookList = remove(bookList, 'On The Electrodynamics of Moving Bodies');
const newestBookList = remove(add(bookList, 'A Brief History of Time'), 'On The Electrodynamics of Moving Bodies');
```

View File

@ -11,7 +11,7 @@ dashedName: remove-elements-from-an-array-using-slice-instead-of-splice
Un'operazione che si fa comunemente lavorando con gli array è quella di rimuovere degli elemento mantenendo il resto dell'array. A questo scopo JavaScript offre il metodo `splice`, che richiede degli argomenti per la posizione (indice) di dove iniziare a rimuovere gli elementi, e per il numero di elementi da rimuovere. Se il secondo argomento non è fornito, il comportamento predefinito è quello di rimuovere gli elementi fino alla fine. Tuttavia, il metodo `splice` muta l'array originale su cui viene chiamato. Ecco un esempio:
```js
var cities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"];
const cities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"];
cities.splice(3, 1);
```
@ -69,7 +69,8 @@ function nonMutatingSplice(cities) {
// Only change code above this line
}
var inputCities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"];
const inputCities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"];
nonMutatingSplice(inputCities);
```
@ -77,10 +78,7 @@ nonMutatingSplice(inputCities);
```js
function nonMutatingSplice(cities) {
// Only change code below this line
return cities.slice(0,3);
// Only change code above this line
}
var inputCities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"];
nonMutatingSplice(inputCities);
const inputCities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"];
```

Some files were not shown because too many files have changed in this diff Show More