Tell us what’s happening:
Your code so far
// Setup
var total = 0;
var myArr = [ 2, 3, 4, 5, 6];
for(i=0; i<=myArr.length; i++){
total += myArr[i];
}
// Only change code below this line
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36
.
Challenge: Iterate Through an Array with a For Loop
Link to the challenge:
Learn to code. Build projects. Earn certifications.Since 2015, 40,000 graduates have gotten jobs at tech companies including Google, Apple, Amazon, and Microsoft.
// Setup
var total = 0;
var i = 0;
var myArr = [ 2, 3, 4, 5, 6];
for(i=0; i<=myArr.length; i++){
total += myArr[i];
}
like thiss? bc it does not work
acskck
April 4, 2020, 2:10pm
4
@pabloalonnso29 you should only loop through the length of your array. If you start from i=0 then you need to stop at arr.length. Rethink your loop parameters again. It is only a simple fix