chore(i18n,curriculum): update translations (#44138)

This commit is contained in:
camperbot
2021-11-06 08:56:52 -07:00
committed by GitHub
parent 09b1592a53
commit 9385d7997b
69 changed files with 685 additions and 619 deletions

View File

@ -17,7 +17,7 @@ dashedName: assignment-with-a-returned-value
ourSum = sum(5, 12);
```
調用函數 `sum`函數返回 `17`,然後將該值賦給變量 `ourSum`
將調用 `sum` 函數,該函數返回 `17` 的值並將其分配給 `ourSum` 變量
# --instructions--
@ -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

@ -25,7 +25,7 @@ dashedName: comparison-with-the-inequality-operator
# --instructions--
`if` 語句中添加不等運算符 `!=`,這樣函數在 `val` 不等於 `99` 的時候,會返回 `Not Equal`
`if` 語句中添加不等運算符 `!=` 以便函數在 `val` 不等於 `99` 時返回字符串 `Not Equal`
# --hints--

View File

@ -26,7 +26,7 @@ dashedName: comparison-with-the-strict-equality-operator
# --instructions--
`if` 語句中,添加嚴格相等運算符,這樣函數在`val` 嚴格等於 `7` 的時候,會返回 `Equal`
`if` 語句中使用嚴格相等運算符,這樣當 `val` 嚴格等於 `7` 時,函數將返回字符串 `Equal`
# --hints--

View File

@ -22,7 +22,7 @@ dashedName: concatenating-strings-with-plus-operator
例如:
```js
var ourStr = "I come first. " + "I come second.";
const ourStr = "I come first. " + "I come second.";
```
字符串 `I come first. I come second.` 將顯示在控制檯中。
@ -44,10 +44,10 @@ assert(myStr === 'This is the start. This is the end.');
assert(code.match(/(["']).*\1\s*\+\s*(["']).*\2/g));
```
應使用 `var` 關鍵字創建 `myStr`
`myStr` 應該使用 `const` 關鍵字創建
```js
assert(/var\s+myStr/.test(code));
assert(/const\s+myStr/.test(code));
```
應把結果賦值給 `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,13 +16,14 @@ dashedName: count-backwards-with-a-for-loop
設置 `i = 10`,並且當 `i > 0` 的時候才繼續循環。 我們使用 `i -= 2` 來讓 `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` 的值爲 `[10,8,6,4,2]`。 讓我們改變初始值和最後的表達式,這樣我們就可以按照奇數從後往前兩兩倒着數。
`ourArray` 現在將包含 `[10, 8, 6, 4, 2]`。 讓我們改變初始值和最後的表達式,這樣我們就可以按照奇數從後往前兩兩倒着數。
# --instructions--
@ -42,7 +43,7 @@ assert(/for\s*\([^)]+?\)/.test(code));
assert(code.match(/myArray.push/));
```
`myArray` 應該等於 `[9,7,5,3,1]`
`myArray` 應該等於 `[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

@ -1,6 +1,6 @@
---
id: 587d7b87367417b2b2512b41
title: 用 const 關鍵字聲明只讀變量
title: 使用 const 關鍵字聲明只讀變量
challengeType: 1
forumTopicId: 301201
dashedName: declare-a-read-only-variable-with-the-const-keyword
@ -8,50 +8,62 @@ dashedName: declare-a-read-only-variable-with-the-const-keyword
# --description--
`let` 並不是唯一的新的聲明變量的方式。 在 ES6 裏面,你還可以使用 `const` 關鍵字聲明變量。
關鍵字 `let` 並不是聲明變量的唯一新方法。 在 ES6 ,你還可以使用 `const` 關鍵字聲明變量。
`const` `let` 的所有優點,不同的是,通過 `const` 聲明的變量是隻讀的。 這意味着通過 `const` 聲明的變量只能被賦值一次,而不能被再次賦值
`const` `let` 的所有出色功能,另外還有一個額外的好處,即使用 `const` 聲明的變量是隻讀的。 它們是一個常量值,這意味着一旦一個變量被賦值爲 `const`,它就不能被重新賦值
```js
const FAV_PET = "Cats";
FAV_PET = "Dogs";
```
控制檯將由於給 `FAV_PET` 重新賦值而顯示錯誤。
由於重新分配 `FAV_PET` 的值,控制檯將顯示錯誤。
可見,嘗試給用 `const` 聲明的變量重新賦值會報錯。 你應該使用 `const` 關鍵字來聲明所有不打算再次賦值的變量。 這有助於避免給一個常量進行額外的再次賦值。 一個最佳實踐是對所有常量的命名採用全大寫字母,並在單詞之間使用下劃線進行分隔。
你應該始終使用 `const` 關鍵字命名不想重新分配的變量。 這有助於避免給一個常量進行額外的再次賦值。
**注意:**通常,開發者會用大寫字母作爲常量標識符,用小寫字母或者駝峯命名作爲變量(對象或數組)標識符。 後面的挑戰會涉及到在數組中使用小寫變量標識符
命名常量的常見做法是全部使用大寫字母,單詞之間用下劃線分隔
**注意:** 對於不可變值,開發人員通常使用大寫變量標識符,對可變值(對象和數組)使用小寫或駝峯式標識符。 你將在後面的挑戰中瞭解有關對象、數組以及不可變和可變值的更多信息。 同樣在後面的挑戰中,你將看到大寫、小寫或駝峯式變量標識符的示例。
# --instructions--
改變以下代碼,使得所有的變量都使用 `let``const` 關鍵詞來聲明。 當變量將會改變的時候使用 `let` 關鍵字,當變量保持常量的時候使用 `const` 關鍵字。 同時,對使`const` 聲明的變量按照最佳實踐重命名,變量名中的字母應該都是大寫
更改代碼,以便使用 `let``const` 聲明所有變量。 當你希望變量改變時使用 `let`,而當你希望變量保持不變時使用 `const`。 此外,重命名`const` 聲明的變量以符合常見做法,這意味着常量應該全部大寫。
# --hints--
代碼中不應有 `var`
`var` 不應存在於你的代碼中
```js
(getUserInput) => assert(!getUserInput('index').match(/var/g));
```
`SENTENCE` 應該是使用 `const` 聲明的常量
你應該將 `fCC` 更改爲全部大寫
```js
(getUserInput) => assert(getUserInput('index').match(/(const SENTENCE)/g));
(getUserInput) => {
assert(getUserInput('index').match(/(FCC)/));
assert(!getUserInput('index').match(/fCC/));
}
```
`i` 應該是使`let`聲明的。
`FCC` 應該是一個`const` 聲明的常量變量
```js
(getUserInput) => assert(getUserInput('index').match(/(let i)/g));
assert.equal(FCC, 'freeCodeCamp');
assert.match(code, /const\s+FCC/);
```
`console.log` 應該修改爲用於打印 `SENTENCE` 變量
`fact` 應該用 `let` 聲明
```js
(getUserInput) => assert(getUserInput('index').match(/(let fact)/g));
```
`console.log` 應該更改爲打印 `FCC``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,18 @@ FAV_PET = "Dogs";
## --seed-contents--
```js
function printManyTimes(str) {
// 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");
var fCC = "freeCodeCamp"; // Change this line
var fact = "is cool!"; // Change this line
fact = "is awesome!";
console.log(fCC, fact); // Change this line
```
# --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,21 +9,27 @@ dashedName: declare-string-variables
# --description--
之前我們寫過這樣的代碼
之前,你使用以下代碼聲明變量
```js
var myName;
```
但是你也可以像這樣聲明一個字符串變量:
```js
var myName = "your name";
```
`"your name"` 被稱<dfn>字符串</dfn><dfn>字面量</dfn>這是一個字符串,因爲它是一系列包含在單引號或雙引號中的零或多個字符。
`"your name"` 被稱<dfn>string</dfn> <dfn>literal</dfn>字符串文字或字符串是用單引號或雙引號括起來的一系列零個或多個字符。
# --instructions--
創建兩個新的字符串變量:`myFirstName``myLastName`,並用你的姓和名分別爲它們賦值。
創建兩個新的字符串變量:`myFirstName``myLastName`,並分別爲它們分配你的名字和姓氏的值。
# --hints--
`myFirstName` 應該是一個字符串,至少包含一個字符。
`myFirstName` 應該是一個至少包含一個字符的字符串
```js
assert(
@ -41,7 +47,7 @@ assert(
);
```
`myLastName` 應該是一個字符串,至少包含一個字符。
`myLastName` 應該是一個至少包含一個字符的字符串
```js
assert(

View File

@ -8,55 +8,53 @@ dashedName: explore-differences-between-the-var-and-let-keywords
# --description--
使用 `var` 關鍵字聲明變量,會出現重複聲明導致變量被覆蓋卻不會報錯的問題。
使用 `var` 關鍵字聲明變量的最大問題之一是你可以輕鬆覆蓋變量聲明:
```js
var camper = 'James';
var camper = 'David';
var camper = "James";
var camper = "David";
console.log(camper);
```
這裏控制檯顯示字符串 `David`
在上面的代碼中,`camper` 變量最初聲明爲 `James`,然後被覆蓋爲 `David`。 然後控制檯顯示字符串 `David`
在上面的代碼中,`camper` 變量的初始值爲 `James`,然後又被覆蓋成了 `David`在小型應用中,你可能不會遇到這樣的問題。但是你的代碼規模變得更加龐大的時候,就可能會在不經意間覆蓋了之前定義的變量。 因爲這樣的情況不會報錯,所以搜索和修復 bug 會變得非常困難。
在 ES6 中引入了新的關鍵字 `let` 來解決 `var` 關鍵字帶來的潛在問題。 如果你在上面的代碼中使用 `let` 關鍵字來代替 `var` 關鍵字,結果會是一個報錯。
在小型應用程序中,你可能不會遇到此類問題。 但是隨着你的代碼庫變大,你可能會意外地覆蓋一個你不打算覆蓋的變量。 由於此行爲不會引發錯誤,因此搜索和修復錯誤變得更加困難。
ES6 中引入了一個名爲 `let` 的關鍵字,這是對 JavaScript 的一次重大更新,以解決與 `var` 關鍵字有關的潛在問題。 你將在後面的挑戰中瞭解其他 ES6 特性。
如果將上面代碼中的 `var` 替換爲 `let` ,則會導致錯誤:
```js
let camper = 'James';
let camper = 'David';
let camper = "James";
let camper = "David";
```
可以在瀏覽器控制檯裏看見這個錯誤。 與 `var` 不同的是,當使用 `let` 的時候,同一名字的變量只能被聲明一次。 請注意 `"use strict"`。 這代表着開啓了嚴格模式,用於檢測常見的代碼錯誤以及“不安全”的行爲, 例如:
該錯誤可以在你的瀏覽器控制檯中看到。
```js
"use strict";
x = 3.14;
```
這將顯示一個錯誤 `x is not defined`
所以不像 `var`,當你使用 `let` 時,同名的變量只能聲明一次。
# --instructions--
更新這段代碼,使用 `let` 關鍵字。
更新代碼,使其僅使用 `let` 關鍵字。
# --hints--
代碼中不應有 `var`
`var` 不應存在於代碼中。
```js
(getUserInput) => assert(!getUserInput('index').match(/var/g));
```
`catName` 變量的值應該爲 `Oliver`
`catName` 應該是字符串 `Oliver`
```js
assert(catName === 'Oliver');
```
`quote` 變量的值應該爲 `Oliver says Meow!`
`catSound` 應該是字符串 `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);
字符串 `10` 將會出現在控制檯中。
例如,如果我們創建了一個變量 `var firstName = "Ada"`,我們可以通過使用 `firstName.length` 屬性來獲得字符串 `Ada` 的長度。
例如,如果我們創建了一個變量 `const firstName = "Ada"`,我們可以通過使用 `firstName.length` 找出字符串 `Ada` 的長度屬性
# --instructions--
@ -29,8 +29,8 @@ console.log("Alan Peter".length);
```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

@ -11,13 +11,13 @@ dashedName: global-scope-and-functions
在 JavaScript 中,<dfn>作用域</dfn>涉及到變量的作用範圍。 在函數外定義的變量具有 <dfn>全局</dfn> 作用域。 這意味着,具有全局作用域的變量可以在代碼的任何地方被調用。
這些沒有使用 `var` 關鍵字定義的變量,會被自動創建`global` 作用域中,形成全局變量。 當在代碼其他地方無意間定義了一個變量,剛好變量名與全局變量相同,這時會產生意想不到的後果。 因此你應該總是使`var` 關鍵字來聲明你的變量。
使用 `let``const` 關鍵字聲明的變量`global` 範圍內自動創建。 當在代碼其他地方無意間定義了一個變量,剛好變量名與全局變量相同,這時會產生意想不到的後果。 你應該總是用 `let``const` 聲明你的變量。
# --instructions--
使用 `var`,在函數外聲明一個全局變量 `myGlobal` 並給它一個初始值 `10`
使用 `let``const`,在任何函數外聲明一個名爲 `myGlobal` 的全局變量。 並給它一個初始值 `10`
在函數 `fun1` 的內部***不***使用 `var` 關鍵字,聲明 `oopsGlobal`,並給它賦值爲 `5`
在函數 `fun1` ***不*** 使用 `let``const` 關鍵字,將 `5` 分配給 `oopsGlobal`
# --hints--
@ -33,10 +33,10 @@ assert(typeof myGlobal != 'undefined');
assert(myGlobal === 10);
```
應使用 `var` 關鍵字定義 `myGlobal`
`myGlobal` 應該使用 `let``const` 關鍵字聲明
```js
assert(/var\s+myGlobal/.test(code));
assert(/(let|const)\s+myGlobal/.test(code));
```
`oopsGlobal` 應爲全局變量,值爲 `5`
@ -109,7 +109,7 @@ function fun2() {
# --solutions--
```js
var myGlobal = 10;
const myGlobal = 10;
function fun1() {
oopsGlobal = 5;

View File

@ -14,13 +14,14 @@ dashedName: iterate-odd-numbers-with-a-for-loop
初始化 `i = 0`,當 `i < 10` 的時候繼續循環。 `i += 2``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` 的值爲 `[0,2,4,6,8]`。 改變計數器(`initialization` ,這樣我們可以用奇數來遞增。
`ourArray` 現在將包含 `[0, 2, 4, 6, 8]`。 改變計數器(`initialization` ,這樣我們可以用奇數來遞增。
# --instructions--
@ -34,7 +35,7 @@ for (var i = 0; i < 10; i += 2) {
assert(/for\s*\([^)]+?\)/.test(code));
```
`myArray` 應該等於 `[1,3,5,7,9]`
`myArray` 應該等於 `[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

@ -15,7 +15,7 @@ JavaScript 中最常見的循環就是 `for`,它可以循環指定次數。
for 循環中的可選三個表達式用分號隔開:
`for (a; b; c)`,其中 `a` 爲初始化語句,`b` 是循環條件語句,`c`終止循環條件表達式。
`for (a; b; c)`,其中`a`爲初始化語句,`b`條件語句,`c`最終的表達式。
初始化語句只會在執行循環開始之前執行一次。 它通常用於定義和設置你的循環變量。
@ -26,13 +26,14 @@ for 循環中的可選三個表達式用分號隔開:
在下面的例子中,先初始化 `i = 0`,條件 `i < 5` 爲 true 時,進入循環。 每次循環後 `i` 的值增加 `1`,然後執行終止循環條件表達式 `i++`
```js
var ourArray = [];
for (var i = 0; i < 5; i++) {
const ourArray = [];
for (let i = 0; i < 5; i++) {
ourArray.push(i);
}
```
最終 `ourArray` 的值爲 `[0,1,2,3,4]`.
`ourArray` 現在的值爲 `[0, 1, 2, 3, 4]`
# --instructions--
@ -46,7 +47,7 @@ for (var i = 0; i < 5; i++) {
assert(/for\s*\([^)]+?\)/.test(code));
```
`myArray` 應該等於 `[1,2,3,4,5]`
`myArray` 應該等於 `[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
我們將學習的第一種類型的循環稱爲 `while` 循環,當 while 指定的條件爲真,循環纔會執行,反之不執行。
```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 @@ while(i < 5) {
assert(code.match(/while/g));
```
`myArray` 應該等於 `[5,4,3,2,1,0]`
`myArray` 應該等於 `[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

@ -16,8 +16,8 @@ dashedName: manipulate-arrays-with-pop
數組中任何類型的元素(數值,字符串,甚至是數組)都可以被彈出來 。
```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 @@ console.log(threeArr);
# --instructions--
使用 `.pop()` 函數移除 `myArray`最後一個元素,並且把彈出的值賦給 `removedFromMyArray`
使用 `.pop()` 函數 `myArray`刪除最後一項,並將取出的值分配給新變量 `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,15 +16,15 @@ dashedName: manipulate-arrays-with-shift
示例:
```js
var ourArray = ["Stimpson", "J", ["cat"]];
var removedFromOurArray = ourArray.shift();
const ourArray = ["Stimpson", "J", ["cat"]];
const removedFromOurArray = ourArray.shift();
```
`removedFromOurArray` 值爲 `Stimpson``ourArray` 值爲 `["J", ["cat"]]`
# --instructions--
使用 `.shift()` 函數移除 `myArray`第一項,並把移出的值賦給 `removedFromMyArray`
使用 `.shift()` 函數 `myArray`刪除第一項,並將“移除的值”值分配給新變量 `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 @@ dashedName: manipulate-arrays-with-unshift
示例:
```js
var ourArray = ["Stimpson", "J", "cat"];
const ourArray = ["Stimpson", "J", "cat"];
ourArray.shift();
ourArray.unshift("Happy");
```
@ -25,7 +25,7 @@ ourArray.unshift("Happy");
# --instructions--
使用 `unshift()` 函數把 `["Paul",35]``myArray` 的頭部
使用 `unshift()` `["Paul", 35]` 加到 `myArray` 變量的開頭
# --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

@ -9,12 +9,12 @@ dashedName: modify-array-data-with-indexes
# --description--
與字符串的數據不可變不同,數組的數據是可變的( <dfn>mutable</dfn>可以自由地改變
與字符串不同,數組的條目是 <dfn>可變的</dfn> 並且可以自由更改,即使數組是用 `const` 聲明的
**示例**
```js
var ourArray = [50,40,30];
const ourArray = [50, 40, 30];
ourArray[0] = 15;
```
@ -28,7 +28,7 @@ ourArray[0] = 15;
# --hints--
`myArray` 應該等於 `[45,64,99]`
`myArray` 現在應該是 `[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,11 +12,12 @@ dashedName: nesting-for-loops
如果你有一個二維數組,可以使用相同的邏輯,先遍歷外面的數組,再遍歷裏面的子數組。 下面是一個例子:
```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 @@ for (var i=0; i < arr.length; i++) {
# --hints--
`multiplyAll([[1],[2],[3]])` 應該返回 `6`
`multiplyAll([[1], [2], [3]])` 應該返回 `6`
```js
assert(multiplyAll([[1], [2], [3]]) === 6);
```
`multiplyAll([[1,2],[3,4],[5,6,7]])` 應該返回 `5040`
`multiplyAll([[1, 2], [3, 4], [5, 6, 7]])` 應該返回 `5040`
```js
assert(
@ -48,7 +49,7 @@ assert(
);
```
`multiplyAll([[5,1],[0.2, 4, 0.5],[3, 9]])` 應該返回 `54`
`multiplyAll([[5, 1], [0.2, 4, 0.5], [3, 9]])` 應該返回 `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

@ -33,43 +33,43 @@ myFun();
# --hints--
`abTest(2,2)` 應該返回一個數字
`abTest(2, 2)` 應該返回一個數字
```js
assert(typeof abTest(2, 2) === 'number');
```
`abTest(2,2)` 應該返回 `8`
`abTest(2, 2)` 應該返回 `8`
```js
assert(abTest(2, 2) === 8);
```
`abTest(-2,2)` 應該返回 `undefined`
`abTest(-2, 2)` 應該返回 `undefined`
```js
assert(abTest(-2, 2) === undefined);
```
`abTest(2,-2)` 應該返回 `undefined`
`abTest(2, -2)` 應該返回 `undefined`
```js
assert(abTest(2, -2) === undefined);
```
`abTest(2,8)` 應該返回 `18`
`abTest(2, 8)` 應該返回 `18`
```js
assert(abTest(2, 8) === 18);
```
`abTest(3,3)` 應該返回 `12`
`abTest(3, 3)` 應該返回 `12`
```js
assert(abTest(3, 3) === 12);
```
`abTest(0,0)` 應該返回 `0`
`abTest(0, 0)` 應該返回 `0`
```js
assert(abTest(0, 0) === 0);

View File

@ -14,7 +14,7 @@ dashedName: returning-boolean-values-from-functions
有時人們通過 `if/else` 語句來做比較,像這樣。
```js
function isEqual(a,b) {
function isEqual(a, b) {
if (a === b) {
return true;
} else {
@ -26,7 +26,7 @@ function isEqual(a,b) {
但有更好的方式來達到相同的效果。 既然 `===` 返回 `true``false` 我們可以直接返回比較結果:
```js
function isEqual(a,b) {
function isEqual(a, b) {
return a === b;
}
```
@ -37,13 +37,13 @@ function isEqual(a,b) {
# --hints--
`isLess(10,15)` 應該返回 `true`
`isLess(10, 15)` 應該返回 `true`
```js
assert(isLess(10, 15) === true);
```
`isLess(15,10)` 應該返回 `false`
`isLess(15, 10)` 應該返回 `false`
```js
assert(isLess(15, 10) === false);

View File

@ -13,13 +13,13 @@ dashedName: use-bracket-notation-to-find-the-first-character-in-a-string
大多數現代編程語言,如 JavaScript不同於人類從 1 開始計數。 它們是從 0 開始計數。 這被稱爲基於零(<dfn>Zero-based</dfn>)的索引。
例如,單詞 `Charles` 的索引 0 的字符是 `C`。 所以 `var firstName = "Charles"`,你可以使用 `firstName[0]` 來獲得第一個位置上的字符
例如,單詞 `Charles` 的索引 0 的字符是 `C`。 所以如果 `const firstName = "Charles"`,你可以通過 `firstName[0]` 得到字符串第一個字母的值
示例:
```js
var firstName = "Charles";
var firstLetter = firstName[0];
const firstName = "Charles";
const firstLetter = firstName[0];
```
`firstLetter` 值爲字符串 `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
要獲取字符串的最後一個字符,可以用字符串的長度減 1 的索引值。
例如,如果 `var firstName = "Ada"` 中,那麼你可以通過 `firstName[firstName.length - 1]` 來得到字符串最後一個字
例如,如果 `const firstName = "Ada"`,則可以使用 `firstName[firstName.length - 1]` 獲取字符串最後一個字母的值
示例:
```js
var firstName = "Ada";
var lastLetter = firstName[firstName.length - 1];
const firstName = "Ada";
const lastLetter = firstName[firstName.length - 1];
```
`lastLetter` 值爲字符串 `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

@ -11,13 +11,13 @@ dashedName: use-bracket-notation-to-find-the-nth-to-last-character-in-a-string
我們既可以獲取字符串的最後一個字符,也可以用獲取字符串的倒數第 N 個字符。
例如,你可以通過 `firstName[firstName.length - 3]` 來獲得 `var firstName = "Augusta"` 字符串的倒數第三個字符。
例如,你可以使用 `firstName[firstName.length - 3]` 獲取 `const firstName = "Augusta"` 字符串的倒數第三個字母的值
例如:
```js
var firstName = "Augusta";
var thirdToLastLetter = firstName[firstName.length - 3];
const firstName = "Augusta";
const thirdToLastLetter = firstName[firstName.length - 3];
```
`thirdToLastLetter` 的值應該爲字符串 `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--
`If` 語句用於在代碼中做條件判斷。 關鍵字 `if` 告訴 JavaScript 在小括號中的條件爲真的情況下去執行定義在大括號裏面的代碼。 這種條件被稱爲 `Boolean` 條件,因爲他們只可能是 `true`(真)或 `false`(假)。
`if` 語句用於在代碼中做出決定。 關鍵字 `if` 告訴 JavaScript 在小括號中的條件爲真的情況下去執行定義在大括號裏面的代碼。 這種條件被稱爲 `Boolean` 條件,因爲他們只可能是 `true`(真)或 `false`(假)。
當條件的計算結果爲 `true`,程序執行大括號內的語句。 當布爾條件的計算結果爲 `false`,大括號內的代碼將不會執行。
@ -22,10 +22,11 @@ dashedName: use-conditional-logic-with-if-statements
```js
function test (myCondition) {
if (myCondition) {
return "It was true";
return "It was true";
}
return "It was false";
}
test(true);
test(false);
```

View File

@ -8,11 +8,13 @@ dashedName: compare-scopes-of-the-var-and-let-keywords
# --description--
使用 `var` 關鍵字來聲明一個變量的時候,這個變量會被聲明成全局變量,或是函數內的局部變量
如果你不熟悉 `let`,請查看 [這個挑戰](/learn/javascript-algorithms-and-data-structures/basic-javascript/explore-differences-between-the-var-and-let-keywords)
`let` 關鍵字的作用與此類似,但會有一些額外的特性。 如果在代碼塊、語句或表達式中使用關鍵字 `let` 聲明變量,這個變量的作用域就被限制在當前的代碼塊、語句或表達式之中
使用 `var` 關鍵字聲明變量時,它是全局聲明的,如果在函數內部聲明則是局部聲明的
舉個例子:
`let` 關鍵字的行爲類似,但有一些額外的功能。 在代碼塊、語句或表達式中使用 `let` 關鍵字聲明變量時,其作用域僅限於該代碼塊、語句或表達式。
例如:
```js
var numArray = [];
@ -23,9 +25,9 @@ console.log(numArray);
console.log(i);
```
這裏控制檯將顯示值 `[0, 1, 2]``3`
此處控制檯將顯示值 `[0, 1, 2]``3`
因爲使用 `var` 關鍵字,`i` 被聲明爲全局變量。 所以當 `i++` 執行時,它會更新全局變量。 這個代碼和下方的代碼類似
使用 `var` 關鍵字,`i` 是全局聲明的。 所以當 `i++` 執行時,它會更新全局變量。 此代碼類似於以下內容
```js
var numArray = [];
@ -37,9 +39,9 @@ console.log(numArray);
console.log(i);
```
這裏控制檯將顯示值 `[0, 1, 2]``3`
此處控制檯將顯示值 `[0, 1, 2]``3`
如果你創建一個函數,將它存儲起來,稍後在使用 `i` 變量的 `for` 循環中使用。這麼做可能會出現問題。 這是因爲存儲的函數會總是指向更新後的全局 `i` 變量的值。
如果你創建一個函數,將它存儲起來,稍後在使用 `i` 變量的 `for` 循環中使用。這麼做可能會出現問題。 這是因爲存儲的函數將始終引用更新後的全局 `i` 變量的值。
```js
var printNumTwo;
@ -53,9 +55,9 @@ for (var i = 0; i < 3; i++) {
console.log(printNumTwo());
```
這裏控制檯將顯示值 `3`
此處控制檯將顯示值 `3`
可以看到,`printNumTwo()` 打印了 3而不是 2。 這是因爲賦值給 `i` 的值已經更新,`printNumTwo()` 返回全局的 `i`,而不是在 for 循環中創建函數時 `i` 的值。 `let` 關鍵字就不會出現這種現象:
可以看到,`printNumTwo()` 打印了 3 而不是 2。 這是因爲賦值給 `i` 的值已經更新,`printNumTwo()` 返回全局的 `i`,而不是在 for 循環中創建函數時 `i` 的值。 `let` 關鍵字就不會出現這種現象:
```js
let printNumTwo;
@ -72,7 +74,7 @@ console.log(i);
在這裏控制檯將顯示值 `2` 和一個錯誤提示 `i is not defined`
`i` 未定義,因爲它沒有在全局範圍內聲明。 它只在 `for` 循環語句中被聲明。 `printNumTwo()` 返回了正確的值,因爲 `let` 關鍵字在循環語句中使 `i` 變量產生了三個不同的值(分別爲 0、1、2
`i` 未定義,因爲它沒有在全局範圍內聲明。 它只在 `for` 循環語句中被聲明。 `printNumTwo()` 返回了正確的值,因爲 `let` 關鍵字創建了三個具有唯一值0、1 和 2的不同 `i` 變量在循環語句中。
# --instructions--

View File

@ -8,11 +8,13 @@ dashedName: mutate-an-array-declared-with-const
# --description--
在現代的 JavaScript 裏,`const` 聲明有很多用法
如果你不熟悉 `const`,請查看[這個挑戰](/learn/javascript-algorithms-and-data-structures/basic-javascript/declare-a-read-only-variable-with-the-const-keyword)
一些開發者傾向於默認使用 `const` 聲明所有變量,除非他們打算後續重新給變量賦值, 那麼他們在聲明的時候就會用 `let`
`const` 聲明在現代 JavaScript 中有很多用例
然而,你要注意,對象(包括數組和函數)在使用 `const` 聲明的時候依然是可變的。 使用 `const` 來聲明只會保證變量不會被重新賦值
默認情況下,一些開發人員更喜歡使用 `const` 分配所有變量,除非他們知道需要重新分配值。 只有在這種情況下,他們才使用 `let`
但是,重要的是要了解使用 `const` 分配給變量的對象(包括數組和函數)仍然是可變的。 使用 `const` 聲明只能防止變量標識符的重新分配。
```js
const s = [5, 6, 7];
@ -21,13 +23,13 @@ s[2] = 45;
console.log(s);
```
`s = [1, 2, 3]` 導致一個錯誤。 `console.log` 顯示值 `[5, 6, 45]`
`s = [1, 2, 3]` 導致錯誤。 `console.log` 顯示值 `[5, 6, 45]`
可以發現,你可以改變對象 `[5, 6, 7]` 本身,變量 `s` 會指向改變後的數組 `[5, 6, 45]`所有數組一樣,數組 `s` 中的元素是可以被改變的,但是因爲使用了 `const` 關鍵字,你不能使用賦值操作符將變量標識 `s` 指向另外一個數組。
如你所見,你可以改變對象 `[5, 6, 7]` 本身,變量 `s` 仍將指向更改後的數組 `[5, 6, 45]`所有數組一樣,`s` 中的數組元素是可變的,但是因爲使用了 `const`,所以不能使用變量標識 `s` 指向一個使用賦值運算符的不同數組。
# --instructions--
這裏有一個使用 `const s = [5, 7, 2]` 聲明的數組。 使用對各元素賦值的方法將數組改成 `[2, 5, 7]`
數組聲明爲 `const s = [5, 7, 2]`。 使用對各元素賦值的方法將數組改成 `[2, 5, 7]`
# --hints--
@ -37,7 +39,7 @@ console.log(s);
(getUserInput) => assert(getUserInput('index').match(/const/g));
```
`s` 應該爲常量(使用 `const`)。
`s` 應該是一個常量變量(通過使用 `const`)。
```js
(getUserInput) => assert(getUserInput('index').match(/const\s+s/g));

View File

@ -10,7 +10,7 @@ dashedName: refactor-global-variables-out-of-functions
目前爲止,我們已經看到了函數式編程的兩個原則:
1) 不要更改變量或對象 - 創建新變量和對象,並在需要時從函數返回它們。 提示:使用類似 `var newArr = arrVar` `arrVar` 是一個數組,代碼只是創建一個對現有變量的引用,而不是副本。 所以更改 `newArr` 中的值會同時更改 `arrVar` 中的值。
1) 不要更改變量或對象 - 創建新變量和對象,並在需要時從函數返回它們。 提示:使用類似 `const newArr = arrVar` 的東西,其中 `arrVar` 是一個數組,只會創建對現有變量的引用,而不是副本。 所以更改 `newArr` 中的值會同時更改 `arrVar` 中的值。
2) 聲明函數參數 - 函數內的任何計算僅取決於參數,而不取決於任何全局對象或變量。
@ -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

@ -55,7 +55,7 @@ assert(code.match(/\s*\.\s*filter/g));
assert(!code.match(/for\s*?\([\s\S]*?\)/g));
```
`filteredList` 應等於 `[{"title": "Inception","rating": "8.8"},{"title": "Interstellar","rating": "8.6"},{"title": "The Dark Knight","rating": "9.0"},{"title": "Batman Begins","rating": "8.3"}]`
`filteredList`等於 `[{"title": "Inception", "rating": "8.8"}, {"title": "Interstellar", "rating": "8.6"}, {"title": "The Dark Knight", "rating": "9.0"}, {"title": "Batman Begins", "rating": "8.3"}]`
```js
assert.deepEqual(filteredList, [
@ -72,7 +72,7 @@ assert.deepEqual(filteredList, [
```js
// The global variable
var watchList = [
const watchList = [
{
"Title": "Inception",
"Year": "2010",
@ -187,7 +187,7 @@ var watchList = [
// Only change code below this line
var filteredList;
const filteredList = "";
// Only change code above this line
@ -197,8 +197,7 @@ console.log(filteredList);
# --solutions--
```js
// The global variable
var watchList = [
const watchList = [
{
"Title": "Inception",
"Year": "2010",
@ -311,7 +310,5 @@ var watchList = [
}
];
// Only change code below this line
let filteredList = watchList.filter(e => e.imdbRating >= 8).map( ({Title: title, imdbRating: rating}) => ({title, rating}) );
// Only change code above this line
const filteredList = watchList.filter(e => e.imdbRating >= 8).map( ({Title: title, imdbRating: rating}) => ({title, rating}) );
```

View File

@ -61,7 +61,7 @@ assert(!code.match(/for\s*?\([\s\S]*?\)/));
assert(code.match(/\.map/g));
```
`ratings` 應等於 `[{"title":"Inception","rating":"8.8"},{"title":"Interstellar","rating":"8.6"},{"title":"The Dark Knight","rating":"9.0"},{"title":"Batman Begins","rating":"8.3"},{"title":"Avatar","rating":"7.9"}]`
`ratings`等於 `[{"title": "Inception", "rating": "8.8"}, {"title": "Interstellar", "rating": "8.6"}, {"title": "The Dark Knight", "rating": "9.0"},{"title": "Batman Begins", "rating": "8.3"}, {"title": "Avatar", "rating": "7.9"}]`
```js
assert.deepEqual(ratings, [
@ -79,7 +79,7 @@ assert.deepEqual(ratings, [
```js
// The global variable
var watchList = [
const watchList = [
{
"Title": "Inception",
"Year": "2010",
@ -194,9 +194,9 @@ var watchList = [
// Only change code below this line
var ratings = [];
for(var i=0; i < watchList.length; i++){
ratings.push({title: watchList[i]["Title"], rating: watchList[i]["imdbRating"]});
const ratings = [];
for (let i = 0; i < watchList.length; i++) {
ratings.push({title: watchList[i]["Title"], rating: watchList[i]["imdbRating"]});
}
// Only change code above this line
@ -207,8 +207,7 @@ console.log(JSON.stringify(ratings));
# --solutions--
```js
// The global variable
var watchList = [
const watchList = [
{
"Title": "Inception",
"Year": "2010",
@ -321,7 +320,7 @@ var watchList = [
}
];
var ratings = watchList.map(function(movie) {
const ratings = watchList.map(function(movie) {
return {
title: movie["Title"],
rating: movie["imdbRating"]