Randell Dawson e9212c61d2 fix(curriculum): Remove unnecessary assert message argument from English challenges JavaScript Algorithms and Data Structures - 01 (#36401)
* fix: rm assert msg basic-javascript

* fix: removed more assert msg args

* fix: fixed verbiage

Co-Authored-By: Parth Parth <34807532+thecodingaviator@users.noreply.github.com>
2019-07-13 08:07:53 +01:00

1.4 KiB

id, title, challengeType, videoUrl
id title challengeType videoUrl
cf1111c1c11feddfaeb1bdef Iterate with JavaScript While Loops 1 https://scrimba.com/c/c8QbnCM

Description

You can run the same code multiple times by using a loop. The first type of loop we will learn is called a while loop because it runs "while" a specified condition is true and stops once that condition is no longer true.
var ourArray = [];
var i = 0;
while(i < 5) {
  ourArray.push(i);
  i++;
}

Let's try getting a while loop to work by pushing values to an array.

Instructions

Push the numbers 0 through 4 to 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));
  - text: <code>myArray</code> should equal <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 = 0;
while(i < 5) {
  myArray.push(i);
  i++;
}