* fix(curriculum): tests quotes * fix(curriculum): fill seed-teardown * fix(curriculum): fix tests and remove unneeded seed-teardown
1.5 KiB
1.5 KiB
id, title, challengeType
id | title | challengeType |
---|---|---|
cf1111c1c11feddfaeb1bdef | Iterate with JavaScript While Loops | 1 |
Description
while
" loop because it runs "while" a specified condition is true and stops once that condition is no longer true.
var ourArray = [];Let's try getting a while loop to work by pushing values to an array.
var i = 0;
while(i < 5) {
ourArray.push(i);
i++;
}
Instructions
myArray
using a while
loop.
Tests
tests:
- text: You should be using a <code>while</code> loop for this.
testString: assert(code.match(/while/g), 'You should be using a <code>while</code> loop for this.');
- text: <code>myArray</code> should equal <code>[0,1,2,3,4]</code>.
testString: assert.deepEqual(myArray, [0,1,2,3,4], '<code>myArray</code> should equal <code>[0,1,2,3,4]</code>.');
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 = 0;
while(i < 5) {
myArray.push(i);
i++;
}