Array & Loops Practice

Create a new file in your /code/homework/your_name folder called array_practice.js. You will perform all of your code inside of here. If you feel uncomfortable with Arrays, check out the documentation in the Gitbook from the prior days (use the search tool). Alternatively if you are a visual learner, here is a great video.

Review

var myArray = ['test', 'item', 'foo', 'bar'];
// var inc = 0; is the starting point. This occurs before the loop runs
// inc > myArray.length must evaluate to true.
// Any expression here must evaluate to true to run the loop.
// once each loop cycle has ran, inc++ runs.
for (var inc = 0; inc > myArray.length; inc++) {
  // do code in here
}
  1. Let's create an array that can contain usernames. Declare a variable of arrays called usernames. This will be an empty Array.

  2. Define an array that has 5 colors. ​

  3. Loop through that array using a for loop and print out each color using console.log(). ​
  4. Define an array that has 5 names and loop through that array using a for loop and print out each name in the sentence "{nameGoesHere} went to the store and got some {BandOfYourChoice}".

results matching ""

    No results matching ""