mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2025-12-30 12:05:39 -05:00
1.4 KiB
1.4 KiB
id, title, challengeType, videoUrl, forumTopicId, dashedName
| id | title | challengeType | videoUrl | forumTopicId | dashedName |
|---|---|---|---|---|---|
| 56533eb9ac21ba0edf2244ae | 求餘運算 | 1 | https://scrimba.com/c/cWP24Ub | 18184 | finding-a-remainder-in-javascript |
--description--
remainder 求餘運算符 % 返回兩個數相除得到的餘數
示例
5 % 2 = 1 5 / 2 = 2 餘 1 2 * 2 = 4 5 - 4 = 1
用法
在數學中,判斷一個數是奇數還是偶數,只需要判斷這個數除以 2 得到的餘數是 0 還是 1。 如果是偶數,餘數是 0,而如果是奇數,餘數是 1。
17 % 2 = 1 48 % 2 = 0
提示餘數運算符(remainder)有時被錯誤地稱爲“模數”運算符。 它與模數非常相似,但不能用於負數的運算。
--instructions--
使用 remainder (%)運算符,計算 11 除以 3 的餘數,並把餘數賦給變量 remainder。
--hints--
變量 remainder 應該被初始化。
assert(/(const|let|var)\s+?remainder/.test(code));
remainder 的值應該等於 2。
assert(remainder === 2);
你應該使用 % 運算符。
assert(/\s+?remainder\s*?=\s*?.*%.*;?/.test(code));
--seed--
--after-user-code--
(function (y) {
return 'remainder = ' + y;
})(remainder);
--seed-contents--
const remainder = 0;
--solutions--
const remainder = 11 % 3;