The test is failing if total is declared with “let” instead of “var”.
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(let i=0; i < myArr.length; i++){
total += myArr[i];
}
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:60.0) Gecko/20100101 Firefox/60.0.
Yes, it runs with the code that was submitted. I had to change it to pass, but wanted to let you all know about the bug with variable declaration using ‘let’.
Yes, when I use “let i = 0” in the loop it fails to pass, when I use “var i = 0” in the loop it passes. I wanted you to know about the issue where “let” is not recognized as a valid declaration.
As I said in my first response, the tests pass with your code including using let. I don’t know what else might have been going on to make your tests fail the first time, but the tests allow you to use let.
In the future, please create your own topic when you have specific questions about your own challenge code. Only respond to another thread when you want to provide help to the original poster of the other thread or have follow up questions concerning other replies given to the original poster.
The easiest way to create a topic for help with your own solution is to click the Ask for Help button located on each challenge. This will automatically import your code in a readable format and pull in the challenge url while still allowing you to ask any question about the challenge or your code.
You cannot declare and initialize the variable total with let because the test is looking for a specific line. You can use let in the loop without any errors.