110 lines
2.6 KiB
Markdown
110 lines
2.6 KiB
Markdown
---
|
|
id: 587d824c367417b2b2512c4d
|
|
title: 比較兩個元素的屬性
|
|
challengeType: 2
|
|
forumTopicId: 301588
|
|
dashedName: compare-the-properties-of-two-elements
|
|
---
|
|
|
|
# --description--
|
|
|
|
請注意,本項目在[這個 Replit 項目](https://replit.com/github/freeCodeCamp/boilerplate-mochachai)的基礎上進行開發。你也可以從 [GitHub](https://repl.it/github/freeCodeCamp/boilerplate-mochachai) 上克隆。
|
|
|
|
# --instructions--
|
|
|
|
在 `tests/1_unit-tests.js` 中,在標有 `#8` 的 `Comparisons` 套件裏,將每個 `assert` 改成 `assert.isAbove` 或 `assert.isAtMost` 方法,讓測試通過(結果應該返回 `true`)。 不要改變傳入斷言的參數。
|
|
|
|
# --hints--
|
|
|
|
不應有未通過的測試
|
|
|
|
```js
|
|
(getUserInput) =>
|
|
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=7').then(
|
|
(data) => {
|
|
assert.equal(data.state, 'passed');
|
|
},
|
|
(xhr) => {
|
|
throw new Error(xhr.responseText);
|
|
}
|
|
);
|
|
```
|
|
|
|
請爲第一個斷言選擇正確的方法 — `isAbove` 或 `isAtMost`。
|
|
|
|
```js
|
|
(getUserInput) =>
|
|
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=7').then(
|
|
(data) => {
|
|
assert.equal(
|
|
data.assertions[0].method,
|
|
'isAtMost',
|
|
'5 is at most (<=) 5'
|
|
);
|
|
},
|
|
(xhr) => {
|
|
throw new Error(xhr.responseText);
|
|
}
|
|
);
|
|
```
|
|
|
|
請爲第二個斷言選擇正確的方法 — `isAbove` 或 `isAtMost`。
|
|
|
|
```js
|
|
(getUserInput) =>
|
|
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=7').then(
|
|
(data) => {
|
|
assert.equal(data.assertions[1].method, 'isAbove', '1 is greater than 0');
|
|
},
|
|
(xhr) => {
|
|
throw new Error(xhr.responseText);
|
|
}
|
|
);
|
|
```
|
|
|
|
請爲第三個斷言選擇正確的方法 — `isAbove` 或 `isAtMost`。
|
|
|
|
```js
|
|
(getUserInput) =>
|
|
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=7').then(
|
|
(data) => {
|
|
assert.equal(
|
|
data.assertions[2].method,
|
|
'isAbove',
|
|
'Math.PI = 3.14159265 is greater than 3'
|
|
);
|
|
},
|
|
(xhr) => {
|
|
throw new Error(xhr.responseText);
|
|
}
|
|
);
|
|
```
|
|
|
|
請爲第四個斷言選擇正確的方法 — `isAbove` 或 `isAtMost`。
|
|
|
|
```js
|
|
(getUserInput) =>
|
|
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=7').then(
|
|
(data) => {
|
|
assert.equal(
|
|
data.assertions[3].method,
|
|
'isAtMost',
|
|
'1 - Math.random() is > 0 and <= 1. It is atMost 1 !'
|
|
);
|
|
},
|
|
(xhr) => {
|
|
throw new Error(xhr.responseText);
|
|
}
|
|
);
|
|
```
|
|
|
|
# --solutions--
|
|
|
|
```js
|
|
/**
|
|
Backend challenges don't need solutions,
|
|
because they would need to be tested against a full working project.
|
|
Please check our contributing guidelines to learn more.
|
|
*/
|
|
```
|