chore(i18n,curriculum): update translations (#42070)
This commit is contained in:
@ -37,7 +37,7 @@ dashedName: add-images-to-your-website
|
|||||||
|
|
||||||
在 `main` 元素裏,給 `p` 元素前面插入一個 `img` 元素。
|
在 `main` 元素裏,給 `p` 元素前面插入一個 `img` 元素。
|
||||||
|
|
||||||
現在設置 `src` 屬性,以便它指向網址 `https://bit.ly/fcc-relaxing-cat`
|
現在設置 `src` 屬性,使它指向網址 `https://www.bit.ly/fcc-relaxing-cat`。
|
||||||
|
|
||||||
最後,不要忘記給 `img` 加上 `alt` 屬性。
|
最後,不要忘記給 `img` 加上 `alt` 屬性。
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ assert($('img').length);
|
|||||||
你的圖片應該有一個 `src` 屬性,其值爲貓咪圖片的 url。
|
你的圖片應該有一個 `src` 屬性,其值爲貓咪圖片的 url。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(/^https:\/\/bit\.ly\/fcc-relaxing-cat$/i.test($('img').attr('src')));
|
assert(/^https:\/\/(www\.)?bit\.ly\/fcc-relaxing-cat$/i.test($('img').attr('src')));
|
||||||
```
|
```
|
||||||
|
|
||||||
你的圖片元素的 `alt` 屬性值不應爲空。
|
你的圖片元素的 `alt` 屬性值不應爲空。
|
||||||
@ -86,7 +86,7 @@ assert(
|
|||||||
```html
|
```html
|
||||||
<h2>CatPhotoApp</h2>
|
<h2>CatPhotoApp</h2>
|
||||||
<main>
|
<main>
|
||||||
<a href="#"><img src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back."></a>
|
<a href="#"><img src="https://www.bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back."></a>
|
||||||
<p>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.</p>
|
<p>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.</p>
|
||||||
<p>Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.</p>
|
<p>Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.</p>
|
||||||
</main>
|
</main>
|
||||||
|
@ -20,7 +20,7 @@ dashedName: create-a-form-element
|
|||||||
|
|
||||||
# --instructions--
|
# --instructions--
|
||||||
|
|
||||||
把現有的 `input` 輸入框放到一個新建的表單 `form` 裏,然後設置 `form` 元素的 `action` 屬性值爲 `"https://freecatphotoapp.com/submit-cat-photo"`。
|
把現有的 `input` 元素嵌套到一個表單 `form` 元素裏,然後設置 `form` 元素的 `action` 屬性值爲 `"https://www.freecatphotoapp.com/submit-cat-photo"`。
|
||||||
|
|
||||||
# --hints--
|
# --hints--
|
||||||
|
|
||||||
@ -34,12 +34,11 @@ assert(
|
|||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
`form` 的 `action` 屬性值應設置爲 `https://freecatphotoapp.com/submit-cat-photo`。
|
`form` 的 `action` 屬性值應爲 `https://www.freecatphotoapp.com/submit-cat-photo`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
const action = $('form').attr('action');
|
||||||
$('form').attr('action') === 'https://freecatphotoapp.com/submit-cat-photo'
|
assert(action.match(/^https:\/\/(www\.)?freecatphotoapp\.com\/submit-cat-photo$/i))
|
||||||
);
|
|
||||||
```
|
```
|
||||||
|
|
||||||
`form` 元素應有開始標籤和結束標籤。
|
`form` 元素應有開始標籤和結束標籤。
|
||||||
@ -61,7 +60,7 @@ assert(
|
|||||||
<main>
|
<main>
|
||||||
<p>Click here to view more <a href="#">cat photos</a>.</p>
|
<p>Click here to view more <a href="#">cat photos</a>.</p>
|
||||||
|
|
||||||
<a href="#"><img src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back."></a>
|
<a href="#"><img src="https://www.bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back."></a>
|
||||||
|
|
||||||
<p>Things cats love:</p>
|
<p>Things cats love:</p>
|
||||||
<ul>
|
<ul>
|
||||||
@ -86,7 +85,7 @@ assert(
|
|||||||
<main>
|
<main>
|
||||||
<p>Click here to view more <a href="#">cat photos</a>.</p>
|
<p>Click here to view more <a href="#">cat photos</a>.</p>
|
||||||
|
|
||||||
<a href="#"><img src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back."></a>
|
<a href="#"><img src="https://www.bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back."></a>
|
||||||
|
|
||||||
<p>Things cats love:</p>
|
<p>Things cats love:</p>
|
||||||
<ul>
|
<ul>
|
||||||
@ -100,7 +99,7 @@ assert(
|
|||||||
<li>thunder</li>
|
<li>thunder</li>
|
||||||
<li>other cats</li>
|
<li>other cats</li>
|
||||||
</ol>
|
</ol>
|
||||||
<form action="https://freecatphotoapp.com/submit-cat-photo">
|
<form action="https://www.freecatphotoapp.com/submit-cat-photo">
|
||||||
<input type="text" placeholder="cat photo URL">
|
<input type="text" placeholder="cat photo URL">
|
||||||
</form>
|
</form>
|
||||||
</main>
|
</main>
|
||||||
|
@ -26,9 +26,9 @@ HTML5 引入了很多更具描述性的 HTML 元素, 包括 `main`、`header`
|
|||||||
|
|
||||||
# --instructions--
|
# --instructions--
|
||||||
|
|
||||||
請在現有的 `p` 之後創建一個新的 `p` 元素,內容爲:`Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.`
|
創建一個新的 `p` 元素,內容爲:`Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.`
|
||||||
|
|
||||||
然後,請添加一個 `main` 元素,作爲現有的兩個 `p` 元素的父級元素。
|
然後,請添加一個 `main` 元素,將現有的兩個 `p` 元素嵌套在這個 `main` 元素裏。
|
||||||
|
|
||||||
# --hints--
|
# --hints--
|
||||||
|
|
||||||
|
@ -14,14 +14,14 @@ dashedName: link-to-external-pages-with-anchor-elements
|
|||||||
`a` 需要一個 `href` 屬性指向跳轉的目的地。 同時,它還應有內容。 例如:
|
`a` 需要一個 `href` 屬性指向跳轉的目的地。 同時,它還應有內容。 例如:
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<a href="https://freecodecamp.org">this links to freecodecamp.org</a>
|
<a href="https://www.freecodecamp.org">this links to freecodecamp.org</a>
|
||||||
```
|
```
|
||||||
|
|
||||||
瀏覽器將顯示文本 `this links to freecodecamp.org`,這是一個可點擊的鏈接。 你可以通過這個鏈接訪問 `https://www.freecodecamp.org`。
|
瀏覽器將顯示文本 `this links to freecodecamp.org`,這是一個可點擊的鏈接。 你可以通過這個鏈接訪問 `https://www.freecodecamp.org`。
|
||||||
|
|
||||||
# --instructions--
|
# --instructions--
|
||||||
|
|
||||||
創建一個內容文本爲 “cat photos” 的 `a` 元素,鏈接指向 `https://freecatphotoapp.com`。
|
創建一個內容文本爲 “cat photos” 的 `a` 元素,鏈接指向 `https://www.freecatphotoapp.com`。
|
||||||
|
|
||||||
# --hints--
|
# --hints--
|
||||||
|
|
||||||
@ -31,10 +31,10 @@ dashedName: link-to-external-pages-with-anchor-elements
|
|||||||
assert(/cat photos/gi.test($('a').text()));
|
assert(/cat photos/gi.test($('a').text()));
|
||||||
```
|
```
|
||||||
|
|
||||||
你的 `a` 元素應鏈接到 `https://freecatphotoapp.com`
|
`a` 元素應鏈接到 `https://www.freecatphotoapp.com`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(/^https?:\/\/freecatphotoapp\.com\/?$/i.test($('a').attr('href')));
|
assert(/^https?:\/\/(www\.)?freecatphotoapp\.com\/?$/i.test($('a').attr('href')));
|
||||||
```
|
```
|
||||||
|
|
||||||
確保 `a` 元素有結束標籤。
|
確保 `a` 元素有結束標籤。
|
||||||
@ -56,7 +56,7 @@ assert(
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<img src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back.">
|
<img src="https://www.bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back.">
|
||||||
|
|
||||||
<p>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.</p>
|
<p>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.</p>
|
||||||
<p>Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.</p>
|
<p>Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.</p>
|
||||||
@ -69,9 +69,9 @@ assert(
|
|||||||
<h2>CatPhotoApp</h2>
|
<h2>CatPhotoApp</h2>
|
||||||
<main>
|
<main>
|
||||||
|
|
||||||
<img src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back.">
|
<img src="https://www.bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back.">
|
||||||
|
|
||||||
<a href="https://freecatphotoapp.com">cat photos</a>
|
<a href="https://www.freecatphotoapp.com">cat photos</a>
|
||||||
<p>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.</p>
|
<p>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.</p>
|
||||||
<p>Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.</p>
|
<p>Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.</p>
|
||||||
</main>
|
</main>
|
||||||
|
@ -15,7 +15,7 @@ dashedName: make-dead-links-using-the-hash-symbol
|
|||||||
|
|
||||||
# --instructions--
|
# --instructions--
|
||||||
|
|
||||||
目前,`href` 的屬性值是 "`https://freecatphotoapp.com`"。 請將 `href` 屬性的值替換爲`#`,以此來創建鏈接佔位符。
|
`href` 屬性的當前值是指向 “`https://www.freecatphotoapp.com`”。 請將 `href` 屬性的值替換爲`#`,以此來創建鏈接佔位符。
|
||||||
|
|
||||||
例如: `href="#"`
|
例如: `href="#"`
|
||||||
|
|
||||||
@ -34,9 +34,9 @@ assert($('a').attr('href') === '#');
|
|||||||
```html
|
```html
|
||||||
<h2>CatPhotoApp</h2>
|
<h2>CatPhotoApp</h2>
|
||||||
<main>
|
<main>
|
||||||
<p>Click here to view more <a href="https://freecatphotoapp.com" target="_blank">cat photos</a>.</p>
|
<p>Click here to view more <a href="https://www.freecatphotoapp.com" target="_blank">cat photos</a>.</p>
|
||||||
|
|
||||||
<img src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back.">
|
<img src="https://www.bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back.">
|
||||||
|
|
||||||
<p>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.</p>
|
<p>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.</p>
|
||||||
<p>Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.</p>
|
<p>Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.</p>
|
||||||
@ -50,7 +50,7 @@ assert($('a').attr('href') === '#');
|
|||||||
<main>
|
<main>
|
||||||
<p>Click here to view more <a href="#" target="_blank">cat photos</a>.</p>
|
<p>Click here to view more <a href="#" target="_blank">cat photos</a>.</p>
|
||||||
|
|
||||||
<img src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back.">
|
<img src="https://www.bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back.">
|
||||||
|
|
||||||
<p>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.</p>
|
<p>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.</p>
|
||||||
<p>Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.</p>
|
<p>Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.</p>
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
id: bad87fee1348bd9aede08817
|
id: bad87fee1348bd9aede08817
|
||||||
title: 將 a 嵌套在段落中
|
title: 將 a 嵌套在段落中
|
||||||
challengeType: 0
|
challengeType: 0
|
||||||
videoUrl: 'https://scrimba.com/p/pVMPUv/cb6k8Cb'
|
|
||||||
forumTopicId: 18244
|
forumTopicId: 18244
|
||||||
dashedName: nest-an-anchor-element-within-a-paragraph
|
dashedName: nest-an-anchor-element-within-a-paragraph
|
||||||
---
|
---
|
||||||
@ -13,7 +12,7 @@ dashedName: nest-an-anchor-element-within-a-paragraph
|
|||||||
|
|
||||||
```html
|
```html
|
||||||
<p>
|
<p>
|
||||||
Here's a <a target="_blank" href="http://freecodecamp.org"> link to freecodecamp.org</a> for you to follow.
|
Here's a <a target="_blank" href="https://www.freecodecamp.org"> link to www.freecodecamp.org</a> for you to follow.
|
||||||
</p>
|
</p>
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -32,18 +31,18 @@ dashedName: nest-an-anchor-element-within-a-paragraph
|
|||||||
`target` 是錨點元素的一個屬性,它用來指定鏈接的打開方式。 屬性值 `_blank` 表示鏈接會在新標籤頁打開。 `href` 是錨點元素的另一個屬性,它用來指定鏈接的 URL:
|
`target` 是錨點元素的一個屬性,它用來指定鏈接的打開方式。 屬性值 `_blank` 表示鏈接會在新標籤頁打開。 `href` 是錨點元素的另一個屬性,它用來指定鏈接的 URL:
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<a href="http://freecodecamp.org"> ... </a>
|
<a href="https://www.freecodecamp.org" target="_blank"> ... </a>
|
||||||
```
|
```
|
||||||
|
|
||||||
`a` 元素內的文本 `link to freecodecamp.org` 叫作<dfn>錨文本</dfn>,會顯示爲一個可以點擊的鏈接:
|
`a` 元素內的文本 `link to www.freecodecamp.org` 叫作<dfn>錨文本</dfn>,會顯示爲一個可以點擊的鏈接:
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<a href=" ... ">link to freecodecamp.org</a>
|
<a href=" ... " target="...">link to freecodecamp.org</a>
|
||||||
```
|
```
|
||||||
|
|
||||||
此示例的最終輸出結果是這樣:
|
此示例的最終輸出結果是這樣:
|
||||||
|
|
||||||
Here's a [link to freecodecamp.org](http://freecodecamp.org) for you to follow.
|
你可以訪問 <a href="https://www.freecodecamp.org" target="_blank">link to www.freecodecamp.org</a>。
|
||||||
|
|
||||||
# --instructions--
|
# --instructions--
|
||||||
|
|
||||||
@ -59,11 +58,11 @@ assert(
|
|||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
`a` 元素應該鏈接到 “`https://freecatphotoapp.com`”。
|
`a` 元素應該鏈接到 “`https://www.freecatphotoapp.com`”。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
$('a[href="https://freecatphotoapp.com"]').length === 1
|
$('a[href="https://www.freecatphotoapp.com"]').length === 1
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -87,7 +86,7 @@ assert($('p') && $('p').length > 2);
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
$('a[href="https://freecatphotoapp.com"]').parent().is('p')
|
$('a[href="https://www.freecatphotoapp.com"]').parent().is('p')
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -95,7 +94,7 @@ assert(
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
$('a[href="https://freecatphotoapp.com"]')
|
$('a[href="https://www.freecatphotoapp.com"]')
|
||||||
.parent()
|
.parent()
|
||||||
.text()
|
.text()
|
||||||
.match(/View\smore\s/gi)
|
.match(/View\smore\s/gi)
|
||||||
@ -140,9 +139,9 @@ assert(
|
|||||||
<h2>CatPhotoApp</h2>
|
<h2>CatPhotoApp</h2>
|
||||||
<main>
|
<main>
|
||||||
|
|
||||||
<a href="https://freecatphotoapp.com" target="_blank">cat photos</a>
|
<a href="https://www.freecatphotoapp.com" target="_blank">cat photos</a>
|
||||||
|
|
||||||
<img src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back.">
|
<img src="https://www.bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back.">
|
||||||
|
|
||||||
<p>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.</p>
|
<p>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.</p>
|
||||||
<p>Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.</p>
|
<p>Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.</p>
|
||||||
@ -154,9 +153,9 @@ assert(
|
|||||||
```html
|
```html
|
||||||
<h2>CatPhotoApp</h2>
|
<h2>CatPhotoApp</h2>
|
||||||
<main>
|
<main>
|
||||||
<p>View more <a target="_blank" href="https://freecatphotoapp.com">cat photos</a></p>
|
<p>View more <a target="_blank" href="https://www.freecatphotoapp.com">cat photos</a></p>
|
||||||
|
|
||||||
<img src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back.">
|
<img src="https://www.bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back.">
|
||||||
|
|
||||||
<p>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.</p>
|
<p>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.</p>
|
||||||
<p>Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.</p>
|
<p>Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.</p>
|
||||||
|
@ -27,7 +27,7 @@ arr[3][0][1];
|
|||||||
|
|
||||||
`arr[3]` 爲 `[[10, 11, 12], 13, 14]`,`arr[3][0]` 爲 `[10, 11, 12]`,並且 `arr[3][0][1]` 爲 `11`。
|
`arr[3]` 爲 `[[10, 11, 12], 13, 14]`,`arr[3][0]` 爲 `[10, 11, 12]`,並且 `arr[3][0][1]` 爲 `11`。
|
||||||
|
|
||||||
**注意:** 數組名與方括號之間不應該有任何空格,比如`array [0][0]` 甚至是 `array [0] [0]` 都是不允許的。 儘管 JavaScript 能夠正確處理這種情況,但是當其他程序員閱讀你寫的代碼時,這可能讓他們感到困惑。
|
**注意:** 數組名與方括號之間不應該有任何空格,比如 `array [0][0]` 甚至是 `array [0] [0]` 都是不允許的。 儘管 JavaScript 能夠正確處理這種情況,但是當其他程序員閱讀你寫的代碼時,這可能讓他們感到困惑。
|
||||||
|
|
||||||
# --instructions--
|
# --instructions--
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ ourPets[1].names[0];
|
|||||||
|
|
||||||
# --instructions--
|
# --instructions--
|
||||||
|
|
||||||
使用對象的點號和數組的方括號從變量 `myPlants` 檢索出第二棵樹。
|
使用點和方括號,將變量 `secondTree` 的值設置爲 `myPlants` 對象中 `trees` 列表的第二個項目。
|
||||||
|
|
||||||
# --hints--
|
# --hints--
|
||||||
|
|
||||||
@ -72,7 +72,6 @@ assert(/=\s*myPlants\[1\].list\[1\]/.test(code));
|
|||||||
## --seed-contents--
|
## --seed-contents--
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// Setup
|
|
||||||
var myPlants = [
|
var myPlants = [
|
||||||
{
|
{
|
||||||
type: "flowers",
|
type: "flowers",
|
||||||
@ -92,9 +91,7 @@ var myPlants = [
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
// Only change code below this line
|
var secondTree = "";
|
||||||
|
|
||||||
var secondTree = ""; // Change this line
|
|
||||||
```
|
```
|
||||||
|
|
||||||
# --solutions--
|
# --solutions--
|
||||||
@ -119,7 +116,5 @@ var myPlants = [
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
// Only change code below this line
|
|
||||||
|
|
||||||
var secondTree = myPlants[1].list[1];
|
var secondTree = myPlants[1].list[1];
|
||||||
```
|
```
|
||||||
|
@ -50,7 +50,7 @@ ourDog.bark = "bow-wow";
|
|||||||
assert(myDog.bark !== undefined);
|
assert(myDog.bark !== undefined);
|
||||||
```
|
```
|
||||||
|
|
||||||
不應該在初始化部分添加 `bark`。
|
不應該在 `myDog` 的初始化中添加 `bark`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(!/bark[^\n]:/.test(code));
|
assert(!/bark[^\n]:/.test(code));
|
||||||
@ -67,7 +67,6 @@ assert(!/bark[^\n]:/.test(code));
|
|||||||
## --seed-contents--
|
## --seed-contents--
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// Setup
|
|
||||||
var myDog = {
|
var myDog = {
|
||||||
"name": "Happy Coder",
|
"name": "Happy Coder",
|
||||||
"legs": 4,
|
"legs": 4,
|
||||||
@ -75,7 +74,7 @@ var myDog = {
|
|||||||
"friends": ["freeCodeCamp Campers"]
|
"friends": ["freeCodeCamp Campers"]
|
||||||
};
|
};
|
||||||
|
|
||||||
// Only change code below this line
|
|
||||||
```
|
```
|
||||||
|
|
||||||
# --solutions--
|
# --solutions--
|
||||||
|
@ -20,7 +20,7 @@ JavaScript有兩種寫註釋的方法。
|
|||||||
// This is an in-line comment.
|
// This is an in-line comment.
|
||||||
```
|
```
|
||||||
|
|
||||||
你也可以使用多行註釋來註釋你的代碼,使用 `/*` 開始, `*/` 結束. 這是一個多行註釋:
|
你也可以使用多行註釋來註釋你的代碼,使用 `/*` 開始, `*/` 結束。 這是一個多行註釋:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
/* This is a
|
/* This is a
|
||||||
|
@ -17,7 +17,7 @@ dashedName: concatenating-strings-with-plus-operator
|
|||||||
'My name is Alan,' + ' I concatenate.'
|
'My name is Alan,' + ' I concatenate.'
|
||||||
```
|
```
|
||||||
|
|
||||||
**提示:**注意空格。 拼接操作不會在兩個字符串之間添加空格。所以,如果想加上空格的話,你需要自己在字符串裏面添加。
|
**提示:** 注意空格。 拼接操作不會在兩個字符串之間添加空格。所以,如果想加上空格的話,你需要自己在字符串裏面添加。
|
||||||
|
|
||||||
例如:
|
例如:
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ dashedName: concatenating-strings-with-the-plus-equals-operator
|
|||||||
|
|
||||||
我們還可以使用 `+=` 運算符來<dfn>拼接</dfn>字符串到現有字符串變量的結尾。 對於那些被分割成幾段的長的字符串來說,這一操作是非常有用的。
|
我們還可以使用 `+=` 運算符來<dfn>拼接</dfn>字符串到現有字符串變量的結尾。 對於那些被分割成幾段的長的字符串來說,這一操作是非常有用的。
|
||||||
|
|
||||||
**提示:**注意空格。 拼接操作不會在兩個字符串之間添加空格,所以,如果想要加上空格的話,你需要自己在字符串裏面添加。
|
**提示:** 注意空格。 拼接操作不會在兩個字符串之間添加空格,所以,如果想要加上空格的話,你需要自己在字符串裏面添加。
|
||||||
|
|
||||||
例如:
|
例如:
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ dashedName: create-decimal-numbers-with-javascript
|
|||||||
|
|
||||||
我們也可以把小數存儲到變量中。 小數有時候也被稱作<dfn>浮點數</dfn>或者 <dfn>floats</dfn>。
|
我們也可以把小數存儲到變量中。 小數有時候也被稱作<dfn>浮點數</dfn>或者 <dfn>floats</dfn>。
|
||||||
|
|
||||||
**提示:**不是所有的實數都可以用浮點數(<dfn>floating point</dfn>)來表示。 因爲可能產生四捨五入的錯誤, [查看詳情](https://en.wikipedia.org/wiki/Floating_point#Accuracy_problems)。
|
**提示:** 不是所有的實數都可以用浮點數(<dfn>floating point</dfn>)來表示。 因爲可能產生四捨五入的錯誤, [查看詳情](https://en.wikipedia.org/wiki/Floating_point#Accuracy_problems)。
|
||||||
|
|
||||||
# --instructions--
|
# --instructions--
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ for (var i = 0; i < arr.length; i++) {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
記住數組的索引從零開始的,這意味着數組的最後一個元素的下標是:`length - 1`(數組的長度 -1)。 我們這個循環的條件是 `i < arr.length`,當 `i` 的值爲 `length` 的時候循環就停止了。 在這個例子中,最後一個循環是 `i === 4`,也就是說,當 `i` 的值等於 `arr.length` 時,結果輸出 `6`。
|
記住數組的索引從零開始的,這意味着數組的最後一個元素的下標是:`length - 1`(數組的長度 -1)。 我們這個循環的條件是 `i < arr.length`,當 `i` 的值爲 `length` 的時候循環就停止了。 在這個例子中,最後一個循環是 `i === 4`,也就是說,當 `i` 的值等於 `arr.length - 1` 時,結果輸出 `6`。 然後 `i` 增加到 `5`,循環會終止,因爲 `i < arr.length` 是 `false`。
|
||||||
|
|
||||||
# --instructions--
|
# --instructions--
|
||||||
|
|
||||||
|
@ -59,65 +59,69 @@ var ourMusic = [
|
|||||||
assert(Array.isArray(myMusic));
|
assert(Array.isArray(myMusic));
|
||||||
```
|
```
|
||||||
|
|
||||||
`myMusic` 應該至少包含兩個元素
|
`myMusic`應該有至少2個元素。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(myMusic.length > 1);
|
assert(myMusic.length > 1);
|
||||||
```
|
```
|
||||||
|
|
||||||
`myMusic[1]` 應該是一個對象
|
`myMusic`元素數組中應該是物體
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(typeof myMusic[1] === 'object');
|
myMusic.forEach(object => {assert.typeOf(object, 'object')})
|
||||||
```
|
```
|
||||||
|
|
||||||
`myMusic[1]` 至少要包含四個屬性
|
`myMusic` 中的對象應該至少有 4 個屬性。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(Object.keys(myMusic[1]).length > 3);
|
myMusic.forEach(object => {assert(Object.keys(object).length > 3); });
|
||||||
```
|
```
|
||||||
|
|
||||||
`myMusic[1]` 應該包含一個類型爲字符串的 `artist` 的屬性
|
`myMusic` 中的對象應該包含一個類型爲字符串的屬性 `artist`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
myMusic.forEach(object => {
|
||||||
myMusic[1].hasOwnProperty('artist') && typeof myMusic[1].artist === 'string'
|
assert.containsAllKeys(object, ['artist']);
|
||||||
);
|
assert.typeOf(object.artist, 'string')
|
||||||
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
`myMusic[1]` 應該包含一個類型爲字符串的 `title` 屬性
|
`myMusic` 中的對象應該包含一個類型爲字符串的屬性 `title`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
myMusic.forEach(object => {
|
||||||
myMusic[1].hasOwnProperty('title') && typeof myMusic[1].title === 'string'
|
assert.containsAllKeys(object, ['title']);
|
||||||
);
|
assert.typeOf(object.title, 'string')
|
||||||
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
`myMusic[1]` 應該包含一個類型爲數字的 `release_year` 屬性
|
`myMusic` 中的對象應該包含一個類型爲數字的屬性 `release_year`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
myMusic.forEach(object => {
|
||||||
myMusic[1].hasOwnProperty('release_year') &&
|
assert.containsAllKeys(object, ['release_year']);
|
||||||
typeof myMusic[1].release_year === 'number'
|
assert.typeOf(object.release_year, 'number')
|
||||||
);
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
`myMusic[1]` 應該包含一個類型爲數組的 `formats` 屬性
|
`myMusic` 中的對象應該包含一個類型爲數組的 `formats` 屬性。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
myMusic.forEach(object => {
|
||||||
myMusic[1].hasOwnProperty('formats') && Array.isArray(myMusic[1].formats)
|
assert.containsAllKeys(object, ['formats']);
|
||||||
);
|
assert.typeOf(object.formats, 'array')
|
||||||
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
`formats`應該是一個至少包含兩個字符串元素的數組
|
`formats`應該是一個至少包含兩個字符串元素的數組
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
myMusic.forEach(object => {
|
||||||
myMusic[1].formats.every(function (item) {
|
object.formats.forEach(format => {
|
||||||
return typeof item === 'string';
|
assert.typeOf(format, 'string')
|
||||||
}) && myMusic[1].formats.length > 1
|
});
|
||||||
);
|
assert.isAtLeast(object.formats.length, 2)
|
||||||
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
# --seed--
|
# --seed--
|
||||||
@ -143,7 +147,6 @@ var myMusic = [
|
|||||||
],
|
],
|
||||||
"gold": true
|
"gold": true
|
||||||
}
|
}
|
||||||
// Add a record here
|
|
||||||
];
|
];
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -20,11 +20,11 @@ ourArray[0] = 15;
|
|||||||
|
|
||||||
`ourArray` 值爲 `[15, 40, 30]`。
|
`ourArray` 值爲 `[15, 40, 30]`。
|
||||||
|
|
||||||
**注意:**數組名與方括號之間不應該有任何空格,比如`array [0]` 。 儘管 JavaScript 能夠正確處理這種情況,但是當其他程序員閱讀你寫的代碼時,這可能讓他們感到困惑。
|
**注意:** 數組名與方括號之間不應該有任何空格,比如 `array [0]` 。 儘管 JavaScript 能夠正確處理這種情況,但是當其他程序員閱讀你寫的代碼時,這可能讓他們感到困惑。
|
||||||
|
|
||||||
# --instructions--
|
# --instructions--
|
||||||
|
|
||||||
將數組 `myArray`中索引爲 `0`上的值修改爲 `45`。
|
將數組 `myArray` 中索引爲 `0` 上的值修改爲 `45`。
|
||||||
|
|
||||||
# --hints--
|
# --hints--
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ myVar = 13 * 13;
|
|||||||
|
|
||||||
# --instructions--
|
# --instructions--
|
||||||
|
|
||||||
改變數值 `0`來讓變量 product 的值等於`80`。
|
改變數值 `0` 來讓變量 product 的值等於`80`。
|
||||||
|
|
||||||
# --hints--
|
# --hints--
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ dashedName: passing-values-to-functions-with-arguments
|
|||||||
|
|
||||||
# --description--
|
# --description--
|
||||||
|
|
||||||
函數的參數 (<dfn>parameters</dfn>)在函數中充當調用函數時傳入函數的輸入佔位符(也叫形參)的作用。 函數調用時,參數可以爲一個或多個。 調用函數時輸入(或傳遞 <dfn>"passed"</dfn>)的實際值被稱爲參數(<dfn>arguments</dfn>)。
|
函數的參數 (<dfn>parameters</dfn>)在函數調用中充當傳入函數的輸入佔位符(也叫形參)。 函數調用時,參數可以爲一個或多個。 調用函數時輸入(或傳遞 <dfn>"passed"</dfn>)的實際值被稱爲參數(<dfn>arguments</dfn>)。
|
||||||
|
|
||||||
這是帶有兩個參數的函數,`param1` 和 `param2`:
|
這是帶有兩個參數的函數,`param1` 和 `param2`:
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ function testFun(param1, param2) {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
然後我們可以調用 `testFun`,就像這樣: `testFun("Hello", "World");`。 我們傳入了兩個字符串參數, `Hello` 和`World`。 在函數中,`param1` 等於字符串 `Hello` 和 `param2` 等於字符串 `World`。 請注意,`testFun` 函數可以多次調用,每次調用時傳遞的參數會決定參數的實際值。
|
然後我們可以調用 `testFun`,就像這樣: `testFun("Hello", "World");`。 我們傳入了兩個字符串參數, `Hello` 和`World`。 在函數中,`param1` 等於字符串 `Hello` 以及 `param2` 等於字符串 `World`。 請注意,`testFun` 函數可以多次調用,每次調用時傳遞的參數會決定參數的實際值。
|
||||||
|
|
||||||
# --instructions--
|
# --instructions--
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ badStr = 'Finn responds, "Let's go!"';
|
|||||||
|
|
||||||
在上面的 <dfn>goodStr</dfn> 中,通過使用反斜槓 `\` 轉義字符可以安全地使用兩種引號。
|
在上面的 <dfn>goodStr</dfn> 中,通過使用反斜槓 `\` 轉義字符可以安全地使用兩種引號。
|
||||||
|
|
||||||
**提示:**不要混淆反斜槓 `\` 和斜槓 `/`。 它們不是一回事。
|
**提示:** 不要混淆反斜槓 `\` 和斜槓 `/`。 它們不是一回事。
|
||||||
|
|
||||||
# --instructions--
|
# --instructions--
|
||||||
|
|
||||||
|
@ -8,21 +8,21 @@ dashedName: record-collection
|
|||||||
|
|
||||||
# --description--
|
# --description--
|
||||||
|
|
||||||
給定一個 JSON 對象,用來表示部分音樂專輯收藏。 每張專輯都有幾個屬性和一個唯一的 id 號作爲鍵值。 並非所有專輯都有完整的信息。
|
給定一個對象,用來表示部分音樂專輯收藏。 每張專輯都有幾個屬性和一個唯一的 id 號作爲鍵值。 並非所有專輯都有完整的信息。
|
||||||
|
|
||||||
以 `updateRecords` 函數開使,這個函數需要一個對象如 `collection`,一個 `id`,一個 `prop` (如 `artist` 或 `tracks`), 和 `value`。 使用下面的規則完成函數來修改傳遞給函數的對象。
|
以 `updateRecords` 函數開始,這個函數需要一個對象 `records`,包含一個音樂專輯集合,一個 `id`,一個 `prop`(如 `artist` 或 `tracks`),和一個 `value`。 使用下面的規則完成函數來修改傳遞給函數的對象。
|
||||||
|
|
||||||
- 你的函數必須始終返回整個對象。
|
- 函數必須始終返回整個音樂專輯集合對象。
|
||||||
- 如果 `prop` 不是 `tracks` 並且 `value` 不是一個空字符串, 將相冊的 `prop` 更新或設置爲 `value`。
|
- 如果 `prop` 不是 `tracks` 並且 `value` 不是一個空字符串, 將相冊的 `prop` 更新或設置爲 `value`。
|
||||||
- 如果 `prop` 是 `tracks` 但專輯沒有 `tracks` 屬性,則應創建空數組併爲其添加 `value`。
|
- 如果 `prop` 是 `tracks` 但專輯沒有 `tracks` 屬性,則應創建空數組併爲其添加 `value`。
|
||||||
- 如果 `prop` 是 `tracks` 並且 `value` 不是一個空字符串,將 `value` 添加到相冊現有 `tracks` 數組的末尾。
|
- 如果 `prop` 是 `tracks` 並且 `value` 不是一個空字符串,將 `value` 添加到相冊現有 `tracks` 數組的末尾。
|
||||||
- 如果 `value` 是空字符串,從專輯裏刪除指定的 `prop`。
|
- 如果 `value` 是空字符串,從專輯裏刪除指定的 `prop`。
|
||||||
|
|
||||||
**注意:** 用 `collection` 對象做爲測試參數對象。
|
**注意:** 用 `recordCollection` 對象做爲測試參數對象。
|
||||||
|
|
||||||
# --hints--
|
# --hints--
|
||||||
|
|
||||||
執行 `updateRecords(collection, 5439, "artist", "ABBA")` 後, `artist` 應該是字符串 `ABBA`
|
執行 `updateRecords(recordCollection, 5439, "artist", "ABBA")` 後,`artist` 的值應該是字符串 `ABBA`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
@ -31,7 +31,7 @@ assert(
|
|||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
執行 `updateRecords(collection, 5439, "tracks", "Take a Chance on Me")` 後,`tracks` 的最後一個元素應該爲字符串 `Take a Chance on Me`。
|
執行 `updateRecords(recordCollection, 5439, "tracks", "Take a Chance on Me")` 後,`tracks` 的最後一個元素應該爲字符串 `Take a Chance on Me`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
@ -41,14 +41,14 @@ assert(
|
|||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
執行 `updateRecords(collection, 2548, "artist", "")` 後, `artist` 不應被設置
|
執行 `updateRecords(recordCollection, 2548, "artist", "")` 後, `artist` 不應被設置爲任何值。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
updateRecords(_recordCollection, 2548, 'artist', '');
|
updateRecords(_recordCollection, 2548, 'artist', '');
|
||||||
assert(!_recordCollection[2548].hasOwnProperty('artist'));
|
assert(!_recordCollection[2548].hasOwnProperty('artist'));
|
||||||
```
|
```
|
||||||
|
|
||||||
執行 `updateRecords(collection, 1245, "tracks", "Addicted to Love")` 後,`tracks` 的最後一個元素應該爲字符串 `Addicted to Love`。
|
執行 `updateRecords(recordCollection, 1245, "tracks", "Addicted to Love")` 後,`tracks` 的最後一個元素應該爲字符串 `Addicted to Love`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
@ -58,7 +58,7 @@ assert(
|
|||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
執行 `updateRecords(collection, 2468, "tracks", "Free")` 後,`tracks` 的第一個元素應該爲字符串 `1999`。
|
執行 `updateRecords(recordCollection, 2468, "tracks", "Free")` 後,`tracks` 的第一個元素應該爲字符串 `1999`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
@ -68,14 +68,14 @@ assert(
|
|||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
執行 `updateRecords(collection, 2548, "tracks", "")` 後, `tracks` 不應被設置
|
執行 `updateRecords(recordCollection, 2548, "tracks", "")` 後, `tracks` 不應被設置爲任何值。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
updateRecords(_recordCollection, 2548, 'tracks', '');
|
updateRecords(_recordCollection, 2548, 'tracks', '');
|
||||||
assert(!_recordCollection[2548].hasOwnProperty('tracks'));
|
assert(!_recordCollection[2548].hasOwnProperty('tracks'));
|
||||||
```
|
```
|
||||||
|
|
||||||
執行 `updateRecords(collection, 1245, "albumTitle", "Riptide")` 後, `albumTitle` 應該是字符串 `Riptide`
|
執行 `updateRecords(recordCollection, 1245, "albumTitle", "Riptide")` 後,`albumTitle` 的值應該是字符串 `Riptide`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
@ -115,7 +115,7 @@ const _recordCollection = {
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
// Setup
|
// Setup
|
||||||
var collection = {
|
var recordCollection = {
|
||||||
2548: {
|
2548: {
|
||||||
albumTitle: 'Slippery When Wet',
|
albumTitle: 'Slippery When Wet',
|
||||||
artist: 'Bon Jovi',
|
artist: 'Bon Jovi',
|
||||||
@ -136,17 +136,17 @@ var collection = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Only change code below this line
|
// Only change code below this line
|
||||||
function updateRecords(object, id, prop, value) {
|
function updateRecords(records, id, prop, value) {
|
||||||
return object;
|
return records;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateRecords(collection, 5439, 'artist', 'ABBA');
|
updateRecords(recordCollection, 5439, 'artist', 'ABBA');
|
||||||
```
|
```
|
||||||
|
|
||||||
# --solutions--
|
# --solutions--
|
||||||
|
|
||||||
```js
|
```js
|
||||||
var collection = {
|
var recordCollection = {
|
||||||
2548: {
|
2548: {
|
||||||
albumTitle: 'Slippery When Wet',
|
albumTitle: 'Slippery When Wet',
|
||||||
artist: 'Bon Jovi',
|
artist: 'Bon Jovi',
|
||||||
@ -167,15 +167,15 @@ var collection = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Only change code below this line
|
// Only change code below this line
|
||||||
function updateRecords(object, id, prop, value) {
|
function updateRecords(records, id, prop, value) {
|
||||||
if (value === '') delete object[id][prop];
|
if (value === '') delete records[id][prop];
|
||||||
else if (prop === 'tracks') {
|
else if (prop === 'tracks') {
|
||||||
object[id][prop] = object[id][prop] || [];
|
records[id][prop] = records[id][prop] || [];
|
||||||
object[id][prop].push(value);
|
records[id][prop].push(value);
|
||||||
} else {
|
} else {
|
||||||
object[id][prop] = value;
|
records[id][prop] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
return object;
|
return records;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
@ -11,7 +11,7 @@ dashedName: use-bracket-notation-to-find-the-first-character-in-a-string
|
|||||||
|
|
||||||
方括號表示法(<dfn>Bracket notation</dfn>)是一種在字符串中的特定 index(索引)處獲取字符的方法。
|
方括號表示法(<dfn>Bracket notation</dfn>)是一種在字符串中的特定 index(索引)處獲取字符的方法。
|
||||||
|
|
||||||
大多數現代編程語言,如JavaScript,不同於人類從 1 開始計數。 它們是從 0 開始計數。 這被稱爲基於零(<dfn>Zero-based</dfn>)的索引。
|
大多數現代編程語言,如 JavaScript,不同於人類從 1 開始計數。 它們是從 0 開始計數。 這被稱爲基於零(<dfn>Zero-based</dfn>)的索引。
|
||||||
|
|
||||||
例如,單詞 `Charles` 的索引 0 的字符是 `C`。 所以在 `var firstName = "Charles"` 中,你可以使用 `firstName[0]` 來獲得第一個位置上的字符。
|
例如,單詞 `Charles` 的索引 0 的字符是 `C`。 所以在 `var firstName = "Charles"` 中,你可以使用 `firstName[0]` 來獲得第一個位置上的字符。
|
||||||
|
|
||||||
|
@ -23,7 +23,14 @@ function functionName() {
|
|||||||
|
|
||||||
# --instructions--
|
# --instructions--
|
||||||
|
|
||||||
<ol><li>先創建一個名爲 <code>reusableFunction</code> 的函數,這個函數可以打印 <code>"Hi World"</code> 到控制檯上。</li><li>然後調用這個函數。</li></ol>
|
<ol>
|
||||||
|
<li>
|
||||||
|
先創建一個名爲 <code>reusableFunction</code> 的函數,這個函數打印 <code>Hi World</code> 到控制檯上。
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
然後調用這個函數。
|
||||||
|
</li>
|
||||||
|
</ol>
|
||||||
|
|
||||||
# --hints--
|
# --hints--
|
||||||
|
|
||||||
|
@ -180,6 +180,12 @@ assert(telephoneCheck('(555-555-5555') === false);
|
|||||||
assert(telephoneCheck('(555)5(55?)-5555') === false);
|
assert(telephoneCheck('(555)5(55?)-5555') === false);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
`telephoneCheck("55 55-55-555-5")` 應返回 `false`。
|
||||||
|
|
||||||
|
```js
|
||||||
|
assert(telephoneCheck('55 55-55-555-5') === false);
|
||||||
|
```
|
||||||
|
|
||||||
# --seed--
|
# --seed--
|
||||||
|
|
||||||
## --seed-contents--
|
## --seed-contents--
|
||||||
|
@ -21,7 +21,7 @@ dashedName: remove-whitespace-from-start-and-end
|
|||||||
`result` 應該等於 `Hello, World!`
|
`result` 應該等於 `Hello, World!`
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(result == 'Hello, World!');
|
assert(result === 'Hello, World!');
|
||||||
```
|
```
|
||||||
|
|
||||||
你不應該使用 `String.prototype.trim()` 方法。
|
你不應該使用 `String.prototype.trim()` 方法。
|
||||||
@ -30,10 +30,10 @@ assert(result == 'Hello, World!');
|
|||||||
assert(!code.match(/\.?[\s\S]*?trim/));
|
assert(!code.match(/\.?[\s\S]*?trim/));
|
||||||
```
|
```
|
||||||
|
|
||||||
`result` 變量不應該設置爲等於字符串。
|
`result` 變量的值不應該是一個字符串。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(!code.match(/result\s*=\s*".*?"/));
|
assert(!code.match(/result\s*=\s*["'`].*?["'`]/));
|
||||||
```
|
```
|
||||||
|
|
||||||
# --seed--
|
# --seed--
|
||||||
|
@ -37,7 +37,7 @@ dashedName: add-images-to-your-website
|
|||||||
|
|
||||||
在 `main` 元素里,给 `p` 元素前面插入一个 `img` 元素。
|
在 `main` 元素里,给 `p` 元素前面插入一个 `img` 元素。
|
||||||
|
|
||||||
现在设置 `src` 属性,以便它指向网址 `https://bit.ly/fcc-relaxing-cat`
|
现在设置 `src` 属性,使它指向网址 `https://www.bit.ly/fcc-relaxing-cat`。
|
||||||
|
|
||||||
最后,不要忘记给 `img` 加上 `alt` 属性。
|
最后,不要忘记给 `img` 加上 `alt` 属性。
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ assert($('img').length);
|
|||||||
你的图片应该有一个 `src` 属性,其值为猫咪图片的 url。
|
你的图片应该有一个 `src` 属性,其值为猫咪图片的 url。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(/^https:\/\/bit\.ly\/fcc-relaxing-cat$/i.test($('img').attr('src')));
|
assert(/^https:\/\/(www\.)?bit\.ly\/fcc-relaxing-cat$/i.test($('img').attr('src')));
|
||||||
```
|
```
|
||||||
|
|
||||||
你的图片元素的 `alt` 属性值不应为空。
|
你的图片元素的 `alt` 属性值不应为空。
|
||||||
@ -86,7 +86,7 @@ assert(
|
|||||||
```html
|
```html
|
||||||
<h2>CatPhotoApp</h2>
|
<h2>CatPhotoApp</h2>
|
||||||
<main>
|
<main>
|
||||||
<a href="#"><img src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back."></a>
|
<a href="#"><img src="https://www.bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back."></a>
|
||||||
<p>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.</p>
|
<p>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.</p>
|
||||||
<p>Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.</p>
|
<p>Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.</p>
|
||||||
</main>
|
</main>
|
||||||
|
@ -20,7 +20,7 @@ dashedName: create-a-form-element
|
|||||||
|
|
||||||
# --instructions--
|
# --instructions--
|
||||||
|
|
||||||
把现有的 `input` 输入框放到一个新建的表单 `form` 里,然后设置 `form` 元素的 `action` 属性值为 `"https://freecatphotoapp.com/submit-cat-photo"`。
|
把现有的 `input` 元素嵌套到一个表单 `form` 元素里,然后设置 `form` 元素的 `action` 属性值为 `"https://www.freecatphotoapp.com/submit-cat-photo"`。
|
||||||
|
|
||||||
# --hints--
|
# --hints--
|
||||||
|
|
||||||
@ -34,12 +34,11 @@ assert(
|
|||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
`form` 的 `action` 属性值应设置为 `https://freecatphotoapp.com/submit-cat-photo`。
|
`form` 的 `action` 属性值应为 `https://www.freecatphotoapp.com/submit-cat-photo`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
const action = $('form').attr('action');
|
||||||
$('form').attr('action') === 'https://freecatphotoapp.com/submit-cat-photo'
|
assert(action.match(/^https:\/\/(www\.)?freecatphotoapp\.com\/submit-cat-photo$/i))
|
||||||
);
|
|
||||||
```
|
```
|
||||||
|
|
||||||
`form` 元素应有开始标签和结束标签。
|
`form` 元素应有开始标签和结束标签。
|
||||||
@ -61,7 +60,7 @@ assert(
|
|||||||
<main>
|
<main>
|
||||||
<p>Click here to view more <a href="#">cat photos</a>.</p>
|
<p>Click here to view more <a href="#">cat photos</a>.</p>
|
||||||
|
|
||||||
<a href="#"><img src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back."></a>
|
<a href="#"><img src="https://www.bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back."></a>
|
||||||
|
|
||||||
<p>Things cats love:</p>
|
<p>Things cats love:</p>
|
||||||
<ul>
|
<ul>
|
||||||
@ -86,7 +85,7 @@ assert(
|
|||||||
<main>
|
<main>
|
||||||
<p>Click here to view more <a href="#">cat photos</a>.</p>
|
<p>Click here to view more <a href="#">cat photos</a>.</p>
|
||||||
|
|
||||||
<a href="#"><img src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back."></a>
|
<a href="#"><img src="https://www.bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back."></a>
|
||||||
|
|
||||||
<p>Things cats love:</p>
|
<p>Things cats love:</p>
|
||||||
<ul>
|
<ul>
|
||||||
@ -100,7 +99,7 @@ assert(
|
|||||||
<li>thunder</li>
|
<li>thunder</li>
|
||||||
<li>other cats</li>
|
<li>other cats</li>
|
||||||
</ol>
|
</ol>
|
||||||
<form action="https://freecatphotoapp.com/submit-cat-photo">
|
<form action="https://www.freecatphotoapp.com/submit-cat-photo">
|
||||||
<input type="text" placeholder="cat photo URL">
|
<input type="text" placeholder="cat photo URL">
|
||||||
</form>
|
</form>
|
||||||
</main>
|
</main>
|
||||||
|
@ -26,9 +26,9 @@ HTML5 引入了很多更具描述性的 HTML 元素, 包括 `main`、`header`
|
|||||||
|
|
||||||
# --instructions--
|
# --instructions--
|
||||||
|
|
||||||
请在现有的 `p` 之后创建一个新的 `p` 元素,内容为:`Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.`
|
创建一个新的 `p` 元素,内容为:`Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.`
|
||||||
|
|
||||||
然后,请添加一个 `main` 元素,作为现有的两个 `p` 元素的父级元素。
|
然后,请添加一个 `main` 元素,将现有的两个 `p` 元素嵌套在这个 `main` 元素里。
|
||||||
|
|
||||||
# --hints--
|
# --hints--
|
||||||
|
|
||||||
|
@ -14,14 +14,14 @@ dashedName: link-to-external-pages-with-anchor-elements
|
|||||||
`a` 需要一个 `href` 属性指向跳转的目的地。 同时,它还应有内容。 例如:
|
`a` 需要一个 `href` 属性指向跳转的目的地。 同时,它还应有内容。 例如:
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<a href="https://freecodecamp.org">this links to freecodecamp.org</a>
|
<a href="https://www.freecodecamp.org">this links to freecodecamp.org</a>
|
||||||
```
|
```
|
||||||
|
|
||||||
浏览器将显示文本 `this links to freecodecamp.org`,这是一个可点击的链接。 你可以通过这个链接访问 `https://www.freecodecamp.org`。
|
浏览器将显示文本 `this links to freecodecamp.org`,这是一个可点击的链接。 你可以通过这个链接访问 `https://www.freecodecamp.org`。
|
||||||
|
|
||||||
# --instructions--
|
# --instructions--
|
||||||
|
|
||||||
创建一个内容文本为 “cat photos” 的 `a` 元素,链接指向 `https://freecatphotoapp.com`。
|
创建一个内容文本为 “cat photos” 的 `a` 元素,链接指向 `https://www.freecatphotoapp.com`。
|
||||||
|
|
||||||
# --hints--
|
# --hints--
|
||||||
|
|
||||||
@ -31,10 +31,10 @@ dashedName: link-to-external-pages-with-anchor-elements
|
|||||||
assert(/cat photos/gi.test($('a').text()));
|
assert(/cat photos/gi.test($('a').text()));
|
||||||
```
|
```
|
||||||
|
|
||||||
你的 `a` 元素应链接到 `https://freecatphotoapp.com`
|
`a` 元素应链接到 `https://www.freecatphotoapp.com`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(/^https?:\/\/freecatphotoapp\.com\/?$/i.test($('a').attr('href')));
|
assert(/^https?:\/\/(www\.)?freecatphotoapp\.com\/?$/i.test($('a').attr('href')));
|
||||||
```
|
```
|
||||||
|
|
||||||
确保 `a` 元素有结束标签。
|
确保 `a` 元素有结束标签。
|
||||||
@ -56,7 +56,7 @@ assert(
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<img src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back.">
|
<img src="https://www.bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back.">
|
||||||
|
|
||||||
<p>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.</p>
|
<p>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.</p>
|
||||||
<p>Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.</p>
|
<p>Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.</p>
|
||||||
@ -69,9 +69,9 @@ assert(
|
|||||||
<h2>CatPhotoApp</h2>
|
<h2>CatPhotoApp</h2>
|
||||||
<main>
|
<main>
|
||||||
|
|
||||||
<img src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back.">
|
<img src="https://www.bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back.">
|
||||||
|
|
||||||
<a href="https://freecatphotoapp.com">cat photos</a>
|
<a href="https://www.freecatphotoapp.com">cat photos</a>
|
||||||
<p>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.</p>
|
<p>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.</p>
|
||||||
<p>Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.</p>
|
<p>Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.</p>
|
||||||
</main>
|
</main>
|
||||||
|
@ -15,7 +15,7 @@ dashedName: make-dead-links-using-the-hash-symbol
|
|||||||
|
|
||||||
# --instructions--
|
# --instructions--
|
||||||
|
|
||||||
目前,`href` 的属性值是 "`https://freecatphotoapp.com`"。 请将 `href` 属性的值替换为`#`,以此来创建链接占位符。
|
`href` 属性的当前值是指向 “`https://www.freecatphotoapp.com`”。 请将 `href` 属性的值替换为`#`,以此来创建链接占位符。
|
||||||
|
|
||||||
例如: `href="#"`
|
例如: `href="#"`
|
||||||
|
|
||||||
@ -34,9 +34,9 @@ assert($('a').attr('href') === '#');
|
|||||||
```html
|
```html
|
||||||
<h2>CatPhotoApp</h2>
|
<h2>CatPhotoApp</h2>
|
||||||
<main>
|
<main>
|
||||||
<p>Click here to view more <a href="https://freecatphotoapp.com" target="_blank">cat photos</a>.</p>
|
<p>Click here to view more <a href="https://www.freecatphotoapp.com" target="_blank">cat photos</a>.</p>
|
||||||
|
|
||||||
<img src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back.">
|
<img src="https://www.bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back.">
|
||||||
|
|
||||||
<p>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.</p>
|
<p>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.</p>
|
||||||
<p>Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.</p>
|
<p>Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.</p>
|
||||||
@ -50,7 +50,7 @@ assert($('a').attr('href') === '#');
|
|||||||
<main>
|
<main>
|
||||||
<p>Click here to view more <a href="#" target="_blank">cat photos</a>.</p>
|
<p>Click here to view more <a href="#" target="_blank">cat photos</a>.</p>
|
||||||
|
|
||||||
<img src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back.">
|
<img src="https://www.bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back.">
|
||||||
|
|
||||||
<p>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.</p>
|
<p>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.</p>
|
||||||
<p>Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.</p>
|
<p>Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.</p>
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
id: bad87fee1348bd9aede08817
|
id: bad87fee1348bd9aede08817
|
||||||
title: 将 a 嵌套在段落中
|
title: 将 a 嵌套在段落中
|
||||||
challengeType: 0
|
challengeType: 0
|
||||||
videoUrl: 'https://scrimba.com/p/pVMPUv/cb6k8Cb'
|
|
||||||
forumTopicId: 18244
|
forumTopicId: 18244
|
||||||
dashedName: nest-an-anchor-element-within-a-paragraph
|
dashedName: nest-an-anchor-element-within-a-paragraph
|
||||||
---
|
---
|
||||||
@ -13,7 +12,7 @@ dashedName: nest-an-anchor-element-within-a-paragraph
|
|||||||
|
|
||||||
```html
|
```html
|
||||||
<p>
|
<p>
|
||||||
Here's a <a target="_blank" href="http://freecodecamp.org"> link to freecodecamp.org</a> for you to follow.
|
Here's a <a target="_blank" href="https://www.freecodecamp.org"> link to www.freecodecamp.org</a> for you to follow.
|
||||||
</p>
|
</p>
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -32,18 +31,18 @@ dashedName: nest-an-anchor-element-within-a-paragraph
|
|||||||
`target` 是锚点元素的一个属性,它用来指定链接的打开方式。 属性值 `_blank` 表示链接会在新标签页打开。 `href` 是锚点元素的另一个属性,它用来指定链接的 URL:
|
`target` 是锚点元素的一个属性,它用来指定链接的打开方式。 属性值 `_blank` 表示链接会在新标签页打开。 `href` 是锚点元素的另一个属性,它用来指定链接的 URL:
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<a href="http://freecodecamp.org"> ... </a>
|
<a href="https://www.freecodecamp.org" target="_blank"> ... </a>
|
||||||
```
|
```
|
||||||
|
|
||||||
`a` 元素内的文本 `link to freecodecamp.org` 叫作<dfn>锚文本</dfn>,会显示为一个可以点击的链接:
|
`a` 元素内的文本 `link to www.freecodecamp.org` 叫作<dfn>锚文本</dfn>,会显示为一个可以点击的链接:
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<a href=" ... ">link to freecodecamp.org</a>
|
<a href=" ... " target="...">link to freecodecamp.org</a>
|
||||||
```
|
```
|
||||||
|
|
||||||
此示例的最终输出结果是这样:
|
此示例的最终输出结果是这样:
|
||||||
|
|
||||||
Here's a [link to freecodecamp.org](http://freecodecamp.org) for you to follow.
|
你可以访问 <a href="https://www.freecodecamp.org" target="_blank">link to www.freecodecamp.org</a>。
|
||||||
|
|
||||||
# --instructions--
|
# --instructions--
|
||||||
|
|
||||||
@ -59,11 +58,11 @@ assert(
|
|||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
`a` 元素应该链接到 “`https://freecatphotoapp.com`”。
|
`a` 元素应该链接到 “`https://www.freecatphotoapp.com`”。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
$('a[href="https://freecatphotoapp.com"]').length === 1
|
$('a[href="https://www.freecatphotoapp.com"]').length === 1
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -87,7 +86,7 @@ assert($('p') && $('p').length > 2);
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
$('a[href="https://freecatphotoapp.com"]').parent().is('p')
|
$('a[href="https://www.freecatphotoapp.com"]').parent().is('p')
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -95,7 +94,7 @@ assert(
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
$('a[href="https://freecatphotoapp.com"]')
|
$('a[href="https://www.freecatphotoapp.com"]')
|
||||||
.parent()
|
.parent()
|
||||||
.text()
|
.text()
|
||||||
.match(/View\smore\s/gi)
|
.match(/View\smore\s/gi)
|
||||||
@ -140,9 +139,9 @@ assert(
|
|||||||
<h2>CatPhotoApp</h2>
|
<h2>CatPhotoApp</h2>
|
||||||
<main>
|
<main>
|
||||||
|
|
||||||
<a href="https://freecatphotoapp.com" target="_blank">cat photos</a>
|
<a href="https://www.freecatphotoapp.com" target="_blank">cat photos</a>
|
||||||
|
|
||||||
<img src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back.">
|
<img src="https://www.bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back.">
|
||||||
|
|
||||||
<p>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.</p>
|
<p>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.</p>
|
||||||
<p>Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.</p>
|
<p>Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.</p>
|
||||||
@ -154,9 +153,9 @@ assert(
|
|||||||
```html
|
```html
|
||||||
<h2>CatPhotoApp</h2>
|
<h2>CatPhotoApp</h2>
|
||||||
<main>
|
<main>
|
||||||
<p>View more <a target="_blank" href="https://freecatphotoapp.com">cat photos</a></p>
|
<p>View more <a target="_blank" href="https://www.freecatphotoapp.com">cat photos</a></p>
|
||||||
|
|
||||||
<img src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back.">
|
<img src="https://www.bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back.">
|
||||||
|
|
||||||
<p>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.</p>
|
<p>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.</p>
|
||||||
<p>Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.</p>
|
<p>Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.</p>
|
||||||
|
@ -27,7 +27,7 @@ arr[3][0][1];
|
|||||||
|
|
||||||
`arr[3]` 为 `[[10, 11, 12], 13, 14]`,`arr[3][0]` 为 `[10, 11, 12]`,并且 `arr[3][0][1]` 为 `11`。
|
`arr[3]` 为 `[[10, 11, 12], 13, 14]`,`arr[3][0]` 为 `[10, 11, 12]`,并且 `arr[3][0][1]` 为 `11`。
|
||||||
|
|
||||||
**注意:** 数组名与方括号之间不应该有任何空格,比如`array [0][0]` 甚至是 `array [0] [0]` 都是不允许的。 尽管 JavaScript 能够正确处理这种情况,但是当其他程序员阅读你写的代码时,这可能让他们感到困惑。
|
**注意:** 数组名与方括号之间不应该有任何空格,比如 `array [0][0]` 甚至是 `array [0] [0]` 都是不允许的。 尽管 JavaScript 能够正确处理这种情况,但是当其他程序员阅读你写的代码时,这可能让他们感到困惑。
|
||||||
|
|
||||||
# --instructions--
|
# --instructions--
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ ourPets[1].names[0];
|
|||||||
|
|
||||||
# --instructions--
|
# --instructions--
|
||||||
|
|
||||||
使用对象的点号和数组的方括号从变量 `myPlants` 检索出第二棵树。
|
使用点和方括号,将变量 `secondTree` 的值设置为 `myPlants` 对象中 `trees` 列表的第二个项目。
|
||||||
|
|
||||||
# --hints--
|
# --hints--
|
||||||
|
|
||||||
@ -72,7 +72,6 @@ assert(/=\s*myPlants\[1\].list\[1\]/.test(code));
|
|||||||
## --seed-contents--
|
## --seed-contents--
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// Setup
|
|
||||||
var myPlants = [
|
var myPlants = [
|
||||||
{
|
{
|
||||||
type: "flowers",
|
type: "flowers",
|
||||||
@ -92,9 +91,7 @@ var myPlants = [
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
// Only change code below this line
|
var secondTree = "";
|
||||||
|
|
||||||
var secondTree = ""; // Change this line
|
|
||||||
```
|
```
|
||||||
|
|
||||||
# --solutions--
|
# --solutions--
|
||||||
@ -119,7 +116,5 @@ var myPlants = [
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
// Only change code below this line
|
|
||||||
|
|
||||||
var secondTree = myPlants[1].list[1];
|
var secondTree = myPlants[1].list[1];
|
||||||
```
|
```
|
||||||
|
@ -50,7 +50,7 @@ ourDog.bark = "bow-wow";
|
|||||||
assert(myDog.bark !== undefined);
|
assert(myDog.bark !== undefined);
|
||||||
```
|
```
|
||||||
|
|
||||||
不应该在初始化部分添加 `bark`。
|
不应该在 `myDog` 的初始化中添加 `bark`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(!/bark[^\n]:/.test(code));
|
assert(!/bark[^\n]:/.test(code));
|
||||||
@ -67,7 +67,6 @@ assert(!/bark[^\n]:/.test(code));
|
|||||||
## --seed-contents--
|
## --seed-contents--
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// Setup
|
|
||||||
var myDog = {
|
var myDog = {
|
||||||
"name": "Happy Coder",
|
"name": "Happy Coder",
|
||||||
"legs": 4,
|
"legs": 4,
|
||||||
@ -75,7 +74,7 @@ var myDog = {
|
|||||||
"friends": ["freeCodeCamp Campers"]
|
"friends": ["freeCodeCamp Campers"]
|
||||||
};
|
};
|
||||||
|
|
||||||
// Only change code below this line
|
|
||||||
```
|
```
|
||||||
|
|
||||||
# --solutions--
|
# --solutions--
|
||||||
|
@ -20,7 +20,7 @@ JavaScript有两种写注释的方法。
|
|||||||
// This is an in-line comment.
|
// This is an in-line comment.
|
||||||
```
|
```
|
||||||
|
|
||||||
你也可以使用多行注释来注释你的代码,使用 `/*` 开始, `*/` 结束. 这是一个多行注释:
|
你也可以使用多行注释来注释你的代码,使用 `/*` 开始, `*/` 结束。 这是一个多行注释:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
/* This is a
|
/* This is a
|
||||||
|
@ -17,7 +17,7 @@ dashedName: concatenating-strings-with-plus-operator
|
|||||||
'My name is Alan,' + ' I concatenate.'
|
'My name is Alan,' + ' I concatenate.'
|
||||||
```
|
```
|
||||||
|
|
||||||
**提示:**注意空格。 拼接操作不会在两个字符串之间添加空格。所以,如果想加上空格的话,你需要自己在字符串里面添加。
|
**提示:** 注意空格。 拼接操作不会在两个字符串之间添加空格。所以,如果想加上空格的话,你需要自己在字符串里面添加。
|
||||||
|
|
||||||
例如:
|
例如:
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ dashedName: concatenating-strings-with-the-plus-equals-operator
|
|||||||
|
|
||||||
我们还可以使用 `+=` 运算符来<dfn>拼接</dfn>字符串到现有字符串变量的结尾。 对于那些被分割成几段的长的字符串来说,这一操作是非常有用的。
|
我们还可以使用 `+=` 运算符来<dfn>拼接</dfn>字符串到现有字符串变量的结尾。 对于那些被分割成几段的长的字符串来说,这一操作是非常有用的。
|
||||||
|
|
||||||
**提示:**注意空格。 拼接操作不会在两个字符串之间添加空格,所以,如果想要加上空格的话,你需要自己在字符串里面添加。
|
**提示:** 注意空格。 拼接操作不会在两个字符串之间添加空格,所以,如果想要加上空格的话,你需要自己在字符串里面添加。
|
||||||
|
|
||||||
例如:
|
例如:
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ dashedName: create-decimal-numbers-with-javascript
|
|||||||
|
|
||||||
我们也可以把小数存储到变量中。 小数有时候也被称作<dfn>浮点数</dfn>或者 <dfn>floats</dfn>。
|
我们也可以把小数存储到变量中。 小数有时候也被称作<dfn>浮点数</dfn>或者 <dfn>floats</dfn>。
|
||||||
|
|
||||||
**提示:**不是所有的实数都可以用浮点数(<dfn>floating point</dfn>)来表示。 因为可能产生四舍五入的错误, [查看详情](https://en.wikipedia.org/wiki/Floating_point#Accuracy_problems)。
|
**提示:** 不是所有的实数都可以用浮点数(<dfn>floating point</dfn>)来表示。 因为可能产生四舍五入的错误, [查看详情](https://en.wikipedia.org/wiki/Floating_point#Accuracy_problems)。
|
||||||
|
|
||||||
# --instructions--
|
# --instructions--
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ for (var i = 0; i < arr.length; i++) {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
记住数组的索引从零开始的,这意味着数组的最后一个元素的下标是:`length - 1`(数组的长度 -1)。 我们这个循环的条件是 `i < arr.length`,当 `i` 的值为 `length` 的时候循环就停止了。 在这个例子中,最后一个循环是 `i === 4`,也就是说,当 `i` 的值等于 `arr.length` 时,结果输出 `6`。
|
记住数组的索引从零开始的,这意味着数组的最后一个元素的下标是:`length - 1`(数组的长度 -1)。 我们这个循环的条件是 `i < arr.length`,当 `i` 的值为 `length` 的时候循环就停止了。 在这个例子中,最后一个循环是 `i === 4`,也就是说,当 `i` 的值等于 `arr.length - 1` 时,结果输出 `6`。 然后 `i` 增加到 `5`,循环会终止,因为 `i < arr.length` 是 `false`。
|
||||||
|
|
||||||
# --instructions--
|
# --instructions--
|
||||||
|
|
||||||
|
@ -59,65 +59,69 @@ var ourMusic = [
|
|||||||
assert(Array.isArray(myMusic));
|
assert(Array.isArray(myMusic));
|
||||||
```
|
```
|
||||||
|
|
||||||
`myMusic` 应该至少包含两个元素
|
`myMusic`应该有至少2个元素。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(myMusic.length > 1);
|
assert(myMusic.length > 1);
|
||||||
```
|
```
|
||||||
|
|
||||||
`myMusic[1]` 应该是一个对象
|
`myMusic`元素数组中应该是物体
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(typeof myMusic[1] === 'object');
|
myMusic.forEach(object => {assert.typeOf(object, 'object')})
|
||||||
```
|
```
|
||||||
|
|
||||||
`myMusic[1]` 至少要包含四个属性
|
`myMusic` 中的对象应该至少有 4 个属性。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(Object.keys(myMusic[1]).length > 3);
|
myMusic.forEach(object => {assert(Object.keys(object).length > 3); });
|
||||||
```
|
```
|
||||||
|
|
||||||
`myMusic[1]` 应该包含一个类型为字符串的 `artist` 的属性
|
`myMusic` 中的对象应该包含一个类型为字符串的属性 `artist`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
myMusic.forEach(object => {
|
||||||
myMusic[1].hasOwnProperty('artist') && typeof myMusic[1].artist === 'string'
|
assert.containsAllKeys(object, ['artist']);
|
||||||
);
|
assert.typeOf(object.artist, 'string')
|
||||||
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
`myMusic[1]` 应该包含一个类型为字符串的 `title` 属性
|
`myMusic` 中的对象应该包含一个类型为字符串的属性 `title`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
myMusic.forEach(object => {
|
||||||
myMusic[1].hasOwnProperty('title') && typeof myMusic[1].title === 'string'
|
assert.containsAllKeys(object, ['title']);
|
||||||
);
|
assert.typeOf(object.title, 'string')
|
||||||
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
`myMusic[1]` 应该包含一个类型为数字的 `release_year` 属性
|
`myMusic` 中的对象应该包含一个类型为数字的属性 `release_year`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
myMusic.forEach(object => {
|
||||||
myMusic[1].hasOwnProperty('release_year') &&
|
assert.containsAllKeys(object, ['release_year']);
|
||||||
typeof myMusic[1].release_year === 'number'
|
assert.typeOf(object.release_year, 'number')
|
||||||
);
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
`myMusic[1]` 应该包含一个类型为数组的 `formats` 属性
|
`myMusic` 中的对象应该包含一个类型为数组的 `formats` 属性。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
myMusic.forEach(object => {
|
||||||
myMusic[1].hasOwnProperty('formats') && Array.isArray(myMusic[1].formats)
|
assert.containsAllKeys(object, ['formats']);
|
||||||
);
|
assert.typeOf(object.formats, 'array')
|
||||||
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
`formats`应该是一个至少包含两个字符串元素的数组
|
`formats`应该是一个至少包含两个字符串元素的数组
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
myMusic.forEach(object => {
|
||||||
myMusic[1].formats.every(function (item) {
|
object.formats.forEach(format => {
|
||||||
return typeof item === 'string';
|
assert.typeOf(format, 'string')
|
||||||
}) && myMusic[1].formats.length > 1
|
});
|
||||||
);
|
assert.isAtLeast(object.formats.length, 2)
|
||||||
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
# --seed--
|
# --seed--
|
||||||
@ -143,7 +147,6 @@ var myMusic = [
|
|||||||
],
|
],
|
||||||
"gold": true
|
"gold": true
|
||||||
}
|
}
|
||||||
// Add a record here
|
|
||||||
];
|
];
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -20,11 +20,11 @@ ourArray[0] = 15;
|
|||||||
|
|
||||||
`ourArray` 值为 `[15, 40, 30]`。
|
`ourArray` 值为 `[15, 40, 30]`。
|
||||||
|
|
||||||
**注意:**数组名与方括号之间不应该有任何空格,比如`array [0]` 。 尽管 JavaScript 能够正确处理这种情况,但是当其他程序员阅读你写的代码时,这可能让他们感到困惑。
|
**注意:** 数组名与方括号之间不应该有任何空格,比如 `array [0]` 。 尽管 JavaScript 能够正确处理这种情况,但是当其他程序员阅读你写的代码时,这可能让他们感到困惑。
|
||||||
|
|
||||||
# --instructions--
|
# --instructions--
|
||||||
|
|
||||||
将数组 `myArray`中索引为 `0`上的值修改为 `45`。
|
将数组 `myArray` 中索引为 `0` 上的值修改为 `45`。
|
||||||
|
|
||||||
# --hints--
|
# --hints--
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ myVar = 13 * 13;
|
|||||||
|
|
||||||
# --instructions--
|
# --instructions--
|
||||||
|
|
||||||
改变数值 `0`来让变量 product 的值等于`80`。
|
改变数值 `0` 来让变量 product 的值等于`80`。
|
||||||
|
|
||||||
# --hints--
|
# --hints--
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ dashedName: passing-values-to-functions-with-arguments
|
|||||||
|
|
||||||
# --description--
|
# --description--
|
||||||
|
|
||||||
函数的参数 (<dfn>parameters</dfn>)在函数中充当调用函数时传入函数的输入占位符(也叫形参)的作用。 函数调用时,参数可以为一个或多个。 调用函数时输入(或传递 <dfn>"passed"</dfn>)的实际值被称为参数(<dfn>arguments</dfn>)。
|
函数的参数 (<dfn>parameters</dfn>)在函数调用中充当传入函数的输入占位符(也叫形参)。 函数调用时,参数可以为一个或多个。 调用函数时输入(或传递 <dfn>"passed"</dfn>)的实际值被称为参数(<dfn>arguments</dfn>)。
|
||||||
|
|
||||||
这是带有两个参数的函数,`param1` 和 `param2`:
|
这是带有两个参数的函数,`param1` 和 `param2`:
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ function testFun(param1, param2) {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
然后我们可以调用 `testFun`,就像这样: `testFun("Hello", "World");`。 我们传入了两个字符串参数, `Hello` 和`World`。 在函数中,`param1` 等于字符串 `Hello` 和 `param2` 等于字符串 `World`。 请注意,`testFun` 函数可以多次调用,每次调用时传递的参数会决定参数的实际值。
|
然后我们可以调用 `testFun`,就像这样: `testFun("Hello", "World");`。 我们传入了两个字符串参数, `Hello` 和`World`。 在函数中,`param1` 等于字符串 `Hello` 以及 `param2` 等于字符串 `World`。 请注意,`testFun` 函数可以多次调用,每次调用时传递的参数会决定参数的实际值。
|
||||||
|
|
||||||
# --instructions--
|
# --instructions--
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ badStr = 'Finn responds, "Let's go!"';
|
|||||||
|
|
||||||
在上面的 <dfn>goodStr</dfn> 中,通过使用反斜杠 `\` 转义字符可以安全地使用两种引号。
|
在上面的 <dfn>goodStr</dfn> 中,通过使用反斜杠 `\` 转义字符可以安全地使用两种引号。
|
||||||
|
|
||||||
**提示:**不要混淆反斜杠 `\` 和斜杠 `/`。 它们不是一回事。
|
**提示:** 不要混淆反斜杠 `\` 和斜杠 `/`。 它们不是一回事。
|
||||||
|
|
||||||
# --instructions--
|
# --instructions--
|
||||||
|
|
||||||
|
@ -8,21 +8,21 @@ dashedName: record-collection
|
|||||||
|
|
||||||
# --description--
|
# --description--
|
||||||
|
|
||||||
给定一个 JSON 对象,用来表示部分音乐专辑收藏。 每张专辑都有几个属性和一个唯一的 id 号作为键值。 并非所有专辑都有完整的信息。
|
给定一个对象,用来表示部分音乐专辑收藏。 每张专辑都有几个属性和一个唯一的 id 号作为键值。 并非所有专辑都有完整的信息。
|
||||||
|
|
||||||
以 `updateRecords` 函数开使,这个函数需要一个对象如 `collection`,一个 `id`,一个 `prop` (如 `artist` 或 `tracks`), 和 `value`。 使用下面的规则完成函数来修改传递给函数的对象。
|
以 `updateRecords` 函数开始,这个函数需要一个对象 `records`,包含一个音乐专辑集合,一个 `id`,一个 `prop`(如 `artist` 或 `tracks`),和一个 `value`。 使用下面的规则完成函数来修改传递给函数的对象。
|
||||||
|
|
||||||
- 你的函数必须始终返回整个对象。
|
- 函数必须始终返回整个音乐专辑集合对象。
|
||||||
- 如果 `prop` 不是 `tracks` 并且 `value` 不是一个空字符串, 将相册的 `prop` 更新或设置为 `value`。
|
- 如果 `prop` 不是 `tracks` 并且 `value` 不是一个空字符串, 将相册的 `prop` 更新或设置为 `value`。
|
||||||
- 如果 `prop` 是 `tracks` 但专辑没有 `tracks` 属性,则应创建空数组并为其添加 `value`。
|
- 如果 `prop` 是 `tracks` 但专辑没有 `tracks` 属性,则应创建空数组并为其添加 `value`。
|
||||||
- 如果 `prop` 是 `tracks` 并且 `value` 不是一个空字符串,将 `value` 添加到相册现有 `tracks` 数组的末尾。
|
- 如果 `prop` 是 `tracks` 并且 `value` 不是一个空字符串,将 `value` 添加到相册现有 `tracks` 数组的末尾。
|
||||||
- 如果 `value` 是空字符串,从专辑里删除指定的 `prop`。
|
- 如果 `value` 是空字符串,从专辑里删除指定的 `prop`。
|
||||||
|
|
||||||
**注意:** 用 `collection` 对象做为测试参数对象。
|
**注意:** 用 `recordCollection` 对象做为测试参数对象。
|
||||||
|
|
||||||
# --hints--
|
# --hints--
|
||||||
|
|
||||||
执行 `updateRecords(collection, 5439, "artist", "ABBA")` 后, `artist` 应该是字符串 `ABBA`
|
执行 `updateRecords(recordCollection, 5439, "artist", "ABBA")` 后,`artist` 的值应该是字符串 `ABBA`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
@ -31,7 +31,7 @@ assert(
|
|||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
执行 `updateRecords(collection, 5439, "tracks", "Take a Chance on Me")` 后,`tracks` 的最后一个元素应该为字符串 `Take a Chance on Me`。
|
执行 `updateRecords(recordCollection, 5439, "tracks", "Take a Chance on Me")` 后,`tracks` 的最后一个元素应该为字符串 `Take a Chance on Me`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
@ -41,14 +41,14 @@ assert(
|
|||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
执行 `updateRecords(collection, 2548, "artist", "")` 后, `artist` 不应被设置
|
执行 `updateRecords(recordCollection, 2548, "artist", "")` 后, `artist` 不应被设置为任何值。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
updateRecords(_recordCollection, 2548, 'artist', '');
|
updateRecords(_recordCollection, 2548, 'artist', '');
|
||||||
assert(!_recordCollection[2548].hasOwnProperty('artist'));
|
assert(!_recordCollection[2548].hasOwnProperty('artist'));
|
||||||
```
|
```
|
||||||
|
|
||||||
执行 `updateRecords(collection, 1245, "tracks", "Addicted to Love")` 后,`tracks` 的最后一个元素应该为字符串 `Addicted to Love`。
|
执行 `updateRecords(recordCollection, 1245, "tracks", "Addicted to Love")` 后,`tracks` 的最后一个元素应该为字符串 `Addicted to Love`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
@ -58,7 +58,7 @@ assert(
|
|||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
执行 `updateRecords(collection, 2468, "tracks", "Free")` 后,`tracks` 的第一个元素应该为字符串 `1999`。
|
执行 `updateRecords(recordCollection, 2468, "tracks", "Free")` 后,`tracks` 的第一个元素应该为字符串 `1999`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
@ -68,14 +68,14 @@ assert(
|
|||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
执行 `updateRecords(collection, 2548, "tracks", "")` 后, `tracks` 不应被设置
|
执行 `updateRecords(recordCollection, 2548, "tracks", "")` 后, `tracks` 不应被设置为任何值。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
updateRecords(_recordCollection, 2548, 'tracks', '');
|
updateRecords(_recordCollection, 2548, 'tracks', '');
|
||||||
assert(!_recordCollection[2548].hasOwnProperty('tracks'));
|
assert(!_recordCollection[2548].hasOwnProperty('tracks'));
|
||||||
```
|
```
|
||||||
|
|
||||||
执行 `updateRecords(collection, 1245, "albumTitle", "Riptide")` 后, `albumTitle` 应该是字符串 `Riptide`
|
执行 `updateRecords(recordCollection, 1245, "albumTitle", "Riptide")` 后,`albumTitle` 的值应该是字符串 `Riptide`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
@ -115,7 +115,7 @@ const _recordCollection = {
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
// Setup
|
// Setup
|
||||||
var collection = {
|
var recordCollection = {
|
||||||
2548: {
|
2548: {
|
||||||
albumTitle: 'Slippery When Wet',
|
albumTitle: 'Slippery When Wet',
|
||||||
artist: 'Bon Jovi',
|
artist: 'Bon Jovi',
|
||||||
@ -136,17 +136,17 @@ var collection = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Only change code below this line
|
// Only change code below this line
|
||||||
function updateRecords(object, id, prop, value) {
|
function updateRecords(records, id, prop, value) {
|
||||||
return object;
|
return records;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateRecords(collection, 5439, 'artist', 'ABBA');
|
updateRecords(recordCollection, 5439, 'artist', 'ABBA');
|
||||||
```
|
```
|
||||||
|
|
||||||
# --solutions--
|
# --solutions--
|
||||||
|
|
||||||
```js
|
```js
|
||||||
var collection = {
|
var recordCollection = {
|
||||||
2548: {
|
2548: {
|
||||||
albumTitle: 'Slippery When Wet',
|
albumTitle: 'Slippery When Wet',
|
||||||
artist: 'Bon Jovi',
|
artist: 'Bon Jovi',
|
||||||
@ -167,15 +167,15 @@ var collection = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Only change code below this line
|
// Only change code below this line
|
||||||
function updateRecords(object, id, prop, value) {
|
function updateRecords(records, id, prop, value) {
|
||||||
if (value === '') delete object[id][prop];
|
if (value === '') delete records[id][prop];
|
||||||
else if (prop === 'tracks') {
|
else if (prop === 'tracks') {
|
||||||
object[id][prop] = object[id][prop] || [];
|
records[id][prop] = records[id][prop] || [];
|
||||||
object[id][prop].push(value);
|
records[id][prop].push(value);
|
||||||
} else {
|
} else {
|
||||||
object[id][prop] = value;
|
records[id][prop] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
return object;
|
return records;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
@ -11,7 +11,7 @@ dashedName: use-bracket-notation-to-find-the-first-character-in-a-string
|
|||||||
|
|
||||||
方括号表示法(<dfn>Bracket notation</dfn>)是一种在字符串中的特定 index(索引)处获取字符的方法。
|
方括号表示法(<dfn>Bracket notation</dfn>)是一种在字符串中的特定 index(索引)处获取字符的方法。
|
||||||
|
|
||||||
大多数现代编程语言,如JavaScript,不同于人类从 1 开始计数。 它们是从 0 开始计数。 这被称为基于零(<dfn>Zero-based</dfn>)的索引。
|
大多数现代编程语言,如 JavaScript,不同于人类从 1 开始计数。 它们是从 0 开始计数。 这被称为基于零(<dfn>Zero-based</dfn>)的索引。
|
||||||
|
|
||||||
例如,单词 `Charles` 的索引 0 的字符是 `C`。 所以在 `var firstName = "Charles"` 中,你可以使用 `firstName[0]` 来获得第一个位置上的字符。
|
例如,单词 `Charles` 的索引 0 的字符是 `C`。 所以在 `var firstName = "Charles"` 中,你可以使用 `firstName[0]` 来获得第一个位置上的字符。
|
||||||
|
|
||||||
|
@ -23,7 +23,14 @@ function functionName() {
|
|||||||
|
|
||||||
# --instructions--
|
# --instructions--
|
||||||
|
|
||||||
<ol><li>先创建一个名为 <code>reusableFunction</code> 的函数,这个函数可以打印 <code>"Hi World"</code> 到控制台上。</li><li>然后调用这个函数。</li></ol>
|
<ol>
|
||||||
|
<li>
|
||||||
|
先创建一个名为 <code>reusableFunction</code> 的函数,这个函数打印 <code>Hi World</code> 到控制台上。
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
然后调用这个函数。
|
||||||
|
</li>
|
||||||
|
</ol>
|
||||||
|
|
||||||
# --hints--
|
# --hints--
|
||||||
|
|
||||||
|
@ -180,6 +180,12 @@ assert(telephoneCheck('(555-555-5555') === false);
|
|||||||
assert(telephoneCheck('(555)5(55?)-5555') === false);
|
assert(telephoneCheck('(555)5(55?)-5555') === false);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
`telephoneCheck("55 55-55-555-5")` 应返回 `false`。
|
||||||
|
|
||||||
|
```js
|
||||||
|
assert(telephoneCheck('55 55-55-555-5') === false);
|
||||||
|
```
|
||||||
|
|
||||||
# --seed--
|
# --seed--
|
||||||
|
|
||||||
## --seed-contents--
|
## --seed-contents--
|
||||||
|
@ -21,7 +21,7 @@ dashedName: remove-whitespace-from-start-and-end
|
|||||||
`result` 应该等于 `Hello, World!`
|
`result` 应该等于 `Hello, World!`
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(result == 'Hello, World!');
|
assert(result === 'Hello, World!');
|
||||||
```
|
```
|
||||||
|
|
||||||
你不应该使用 `String.prototype.trim()` 方法。
|
你不应该使用 `String.prototype.trim()` 方法。
|
||||||
@ -30,10 +30,10 @@ assert(result == 'Hello, World!');
|
|||||||
assert(!code.match(/\.?[\s\S]*?trim/));
|
assert(!code.match(/\.?[\s\S]*?trim/));
|
||||||
```
|
```
|
||||||
|
|
||||||
`result` 变量不应该设置为等于字符串。
|
`result` 变量的值不应该是一个字符串。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(!code.match(/result\s*=\s*".*?"/));
|
assert(!code.match(/result\s*=\s*["'`].*?["'`]/));
|
||||||
```
|
```
|
||||||
|
|
||||||
# --seed--
|
# --seed--
|
||||||
|
Reference in New Issue
Block a user