Not sure what’s wrong. It says my result correctly totals to 20. But it fails me for " total should be declared and initialized to 0". It seems to me like I declared total and set it to 0. What’s the problem?
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 (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; rv:68.0) Gecko/20100101 Firefox/68.0.
Hi there,
Also a good practice will be to start also at the same time working with modern JS, although i will said i love the regular for loop. I will still think that for best practices to work on other options to create a for loop. Just to understand, many companies might sometimes ask developers for modern JS, and for good practices its good to have alternatives and options, in this case the for loop vs forEach loop.
This will help developers to just dont get stuck in just one option, or maybe when you are reading in someones code, and they have something new for ES6,ES7 will be good to know this new coding upgrades. ? what all think about that. Let me know.