FCC - Iterate with JavaScript While Loops

In this example below you will see how to do a FCC - Iterate with JavaScript While Loops with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by 04rebhop, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright 04rebhop ©
  • HTML
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>FCC - Iterate with JavaScript While Loops</title>
  
  
  
  
  
</head>

<body>

  <!--You can run the same code multiple times by using a loop.

Another type of JavaScript loop 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.  -->
  
  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/04rebhop/fcc-iterate-with-javascript-while-loops-NwwxeJ */

// Setup
var myArray = [];

// Only change code below this line.
var i = 0;
while(i < 5) {
  myArray.push(i);
  i++;
}

Comments