freeCodeCamp/curriculum/challenges/chinese/02-javascript-algorithms-an.../basic-javascript/finding-a-remainder-in-java...

1.9 KiB
Raw Blame History

id title challengeType videoUrl localeTitle
56533eb9ac21ba0edf2244ae Finding a Remainder in JavaScript 1 在JavaScript中查找剩余内容

Description

余数运算符%给出了两个数的除法的余数。
52 = 1因为
Math.floor5/2= 2商数
2 * 2 = 4
5 - 4 = 1剩余
用法
在数学中,通过检查数字除以2的余数,可以检查数字是偶数还是奇数。
172 = 117为奇数
482 = 048为偶数
注意
余数运算符有时被错误地称为“模数”运算符。它与模数非常相似,但在负数下不能正常工作。

Instructions

使用余数 % )运算符将remainder设置为等于11的余数除以3

Tests

tests:
  - text: 应该初始化变量<code>remainder</code>
    testString: 'assert(/var\s+?remainder/.test(code), "The variable <code>remainder</code> should be initialized");'
  - text: <code>remainder</code>的值应为<code>2</code>
    testString: 'assert(remainder === 2, "The value of <code>remainder</code> should be <code>2</code>");'
  - text: 您应该使用<code>%</code>运算符
    testString: 'assert(/\s+?remainder\s*?=\s*?.*%.*;/.test(code), "You should use the <code>%</code> operator");'

Challenge Seed

// Only change code below this line

var remainder;

After Test

console.info('after the test');

Solution

// solution required