1.1 KiB
1.1 KiB
id, title, challengeType, videoUrl, forumTopicId
id | title | challengeType | videoUrl | forumTopicId |
---|---|---|---|---|
56533eb9ac21ba0edf2244ae | 求余运算 | 1 | https://scrimba.com/c/cWP24Ub | 18184 |
--description--
remainder求余运算符%
返回两个数相除得到的余数
示例
5 % 2 = 1 因为
Math.floor(5 / 2) = 2 (商)
2 * 2 = 4
5 - 4 = 1 (余数)
用法
在数学中,判断一个数是奇数还是偶数,只需要判断这个数除以 2 得到的余数是 0 还是 1。
17 % 2 = 1(17 是奇数)
48 % 2 = 0(48 是偶数)
提示
余数运算符(remainder)有时被错误地称为“模数”运算符。它与模数非常相似,但不能用于负数的运算。****
--instructions--
使用%
运算符,计算 11 除以 3 的余数,并把余数赋给变量 remainder。
--hints--
变量remainder
应该被初始化。
assert(/var\s+?remainder/.test(code));
remainder
的值应该等于2
。
assert(remainder === 2);
你应该使用%
运算符。
assert(/\s+?remainder\s*?=\s*?.*%.*;/.test(code));