1.6 KiB
1.6 KiB
id, title, challengeType, videoUrl, forumTopicId, dashedName
id | title | challengeType | videoUrl | forumTopicId | dashedName |
---|---|---|---|---|---|
56533eb9ac21ba0edf2244ae | JavaScript で割り算の余りを求める | 1 | https://scrimba.com/c/cWP24Ub | 18184 | finding-a-remainder-in-javascript |
--description--
剰余演算子 %
は 2 つの数値の割り算の余りを取得します。
例
5 % 2 = 1 なぜならば
Math.floor(5 / 2) = 2 (割り算の商)
2 * 2 = 4
5 - 4 = 1 (割り算の余り)
使用例
数学では、ある数が偶数か奇数かを求めるために、その数を 2
で割った余りを調べることができます。
17 % 2 = 1 (17 は奇数)
48 % 2 = 0 (48 は偶数)
注: 剰余演算子はしばしばモジュロ演算子と混同されることがあります。 剰余はモジュロと非常によく似ていますが、負数では正しく機能しません。
--instructions--
剰余 (%
) 演算子を使用して、remainder
が 11
を 3
で割った余りと等しくなるように設定してください。
--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;