feat: rewrite Iterate with JavaScript While Loops challenge (#37697)
* feat: rewrite Iterate with JavaScript While Loops challenge Previous example in the challenge description was the exact code that challenge instructions say to implement. Change the challenge to differentiate from the example. resolve freeCodeCamp/freeCodeCamp#37694 * fix: update iterate with javascript while loops solution * refactor: improve iterate with js while loops challenge wording Co-Authored-By: Randell Dawson <5313213+RandellDawson@users.noreply.github.com>
This commit is contained in:
@ -25,7 +25,7 @@ Let's try getting a while loop to work by pushing values to an array.
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Push the numbers 0 through 4 to <code>myArray</code> using a <code>while</code> loop.
|
||||
Add the numbers 5 through 0 (inclusive) in descending order to <code>myArray</code> using a <code>while</code> loop.
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
@ -35,8 +35,8 @@ Push the numbers 0 through 4 to <code>myArray</code> using a <code>while</code>
|
||||
tests:
|
||||
- text: You should be using a <code>while</code> loop for this.
|
||||
testString: assert(code.match(/while/g));
|
||||
- text: <code>myArray</code> should equal <code>[0,1,2,3,4]</code>.
|
||||
testString: assert.deepEqual(myArray, [0,1,2,3,4]);
|
||||
- text: <code>myArray</code> should equal <code>[5,4,3,2,1,0]</code>.
|
||||
testString: assert.deepEqual(myArray, [5,4,3,2,1,0]);
|
||||
|
||||
```
|
||||
|
||||
@ -76,10 +76,10 @@ if(typeof myArray !== "undefined"){(function(){return myArray;})();}
|
||||
|
||||
```js
|
||||
var myArray = [];
|
||||
var i = 0;
|
||||
while(i < 5) {
|
||||
var i = 5;
|
||||
while(i >= 0) {
|
||||
myArray.push(i);
|
||||
i++;
|
||||
i--;
|
||||
}
|
||||
```
|
||||
|
||||
|
Reference in New Issue
Block a user