1.5 KiB
1.5 KiB
id, challengeType, videoUrl, forumTopicId, localeTitle
id | challengeType | videoUrl | forumTopicId | localeTitle |
---|---|---|---|---|
cf1111c1c11feddfaeb1bdef | 1 | https://scrimba.com/c/c8QbnCM | 18220 | while 循环 |
Description
while
" 循环,因为它规定,当 "while" 条件为真,循环才会执行,反之不执行。
var ourArray = [];
var i = 0;
while(i < 5) {
ourArray.push(i);
i++;
}
在上面的代码里,while
循环执行 5 次把 0 到 4 的数字添加到 ourArray
数组里。
让我们通过 while 循环将值添加到数组中。
Instructions
while
循环,把从 0 到 4 的值添加到myArray
中。
Tests
tests:
- text: 你应该使用<code>while</code>循环。
testString: assert(code.match(/while/g));
- text: <code>myArray</code>应该等于<code>[0,1,2,3,4]</code>。
testString: assert.deepEqual(myArray, [0,1,2,3,4]);
Challenge Seed
// Setup
var myArray = [];
// Only change code below this line.
After Test
if(typeof myArray !== "undefined"){(function(){return myArray;})();}
Solution
var myArray = [];
var i = 5;
while(i >= 0) {
myArray.push(i);
i--;
}