Iterate Through an Array with a For Loop :I

Tell us what’s happening:

Hi Guys,

Cannot see what more needs to be done here. Your help required and much appreciated

Your code so far

// Example
var ourArr = [ 9, 10, 11, 12];
var ourTotal = 0;

for (var i = 0; i < ourArr.length; i++) {
  ourTotal += ourArr[i];

// Setup
var myArr = [ 2, 3, 4, 5, 6];

// Only change code below this line
var total =  0
for ( i = 0; i < myArr.length; i++) {
   total += myArr[i];

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36.

Link to the challenge:

for ( var i = 0; i < myArr.length; i++)

Even when I put this var in, this does not help

What is the message it gives you? Which test is indicated as failing?

You’re missing a semi-colon:

var total =  0; // <-- Here!
for ( i = 0; i < myArr.length; i++) {
   total += myArr[i];
1 Like

Good find. With modern javascript, semi-colons are optional (and more and more, frowned upon). But it is possible that the FCC terminal kinda barfs on that one.

Hadn’t heard that! Missing semi-colons have been the bane of my coding existence (probably why I found the one above so quickly). I learned Python before JS, and had a heck of a time adjusting to “punctuating” my code. Glad to know others are frowning with me.

1 Like

rofl – I watch “FunFunFunction” a lot on YouTube (highly HIGHLY recommend it), and he frequently goes on a semicolon rant. Makes me giggle a little.

I’ve been coding since MS-BASIC, learned COBOL and RPG-II in college. Kind of used to punctuatificating the heck out of code. :stuck_out_tongue_winking_eye:

1 Like