Week 4: Assignment 3
by Larry Adams
HTML
<h3>Arrays & Looping</h3>
<h4>4 Tasks for this Practice Set:</h4>
<ol>
<li>
Make an Array of strings and assign it to a variable. You may make the strings a list of anything you like and use a variable name of your choice.
<h2>
<p id="q1"></p>
</h2>
</li>
<li>
Using the Array you made in the previous step, iterate over its elements and write each one to the console.
<h2>
<p id="q2"></p>
</h2>
</li>
<li>
Use one of the methods of the Array object to insert a new element to the beginning of your array. Looking through the methods on the Array reference page at <a href="http://www.w3schools.com/jsref/">W3Schools</a> may be helpful.
<p>Placing a new element at the beginning of the array by using unshift.</p>
<h2>
<p id="q3"></p>
</h2>
</li>
<li>
Loop through the integers from 1 to 100 and write each to the console only if it is odd.
<p id="q4"></p>
</li>
</ol>
JavaScript
"use strict";
// Insert your code for #1 here
var cars = ["Saab"," Volvo"," BMW", " Fiat"];
document.getElementById("q1").innerHTML = cars;
console.log(cars)
// Insert your code for #2 here
document.getElementById("q2").innerHTML = cars.join(" | ");
console.log(cars)
// Insert your code for #3 here
var cars = [" Saab"," Volvo"," BMW", " Fiat"];
cars.unshift( "Jaguar" );
document.getElementById("q3").innerHTML = cars;
console.log(cars)
// Insert your code for #4 here var text = "";