Glitch in "For" loop test?

I have been solving the JavaScript tests and this particular challenge asks me to create a For loop to add indexed numbers to a variable called Total. I have completed the challenge and everything looks good except that it doesn’t allow me to pass the challenge because it marks with an X “Do not set the total to 20 directly”. It’s sorta telling me that I set the variable to 20 when in fact I clearly didn’t, it is set to 0 and reaches 20 when the loop is ran. I have watched the videos and my code looks exactly like the solution, not a coma out of place. Has anyone experienced this? Did I do something wrong? What do I need to do to advance?

Your code so far

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

// Only change code below this line
var total = 0; 

for (var 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/64.0.3282.140 Safari/537.36 Edge/18.17763.

Challenge: Iterate Through an Array with a For Loop

Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/iterate-through-an-array-with-a-for-loop

Yes, this appears to be a real glitch. I pasted the solution code to test if it’s a bug on Google Chrome (OS: Ubuntu 18.04) and got the same problem. Let’s see if others are experiencing the same issue. I’ve tried other ways to solve the challenge and get the same issue.

I managed to pass the test by first typing up the function and declaring the variable after that. For some reason that made it work. As a beginner, learning to type JavaScript Is frustrating enough (not necessarily because of the logic but all the intricacies of how to write it) without the environment being uncooperative.

@RandellDawson, this appears to be a real bug. Are you able to reproduce it by any chance?

@arjunnij Can you post the code you are trying to use for the solution?

I noticed that if you copy/paste the solution on the first post you get that alert of " Do not set total to 20 directly".

If you writing yourself the solution you will pass.

Quite odd. We need to know what is happening in the validator function to find out the cause of this behaviour.

Could the case that the validator is checking that the user has typed the solution instead of copy/paste or does have a minimum limit of key strokes required?

@RandellDawson @GeorgeCrisan Well I tried to solve it myself first - typing it in manually - and got the same result. Here is my code:

// 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(var j = 0; j < myArr.length; j++) { 
  total += myArr[j]; 
}

Definitely appears to be an issue with the validator - I haven’t tried on other browsers or operating systems.

There is a bug in the test. I will submit a fix now. The test has a problem with the extra space character at the end of the following line:

var total = 0; 
1 Like