Basic JavaScript - Iterate Through an Array with a For Loop

Tell us what’s happening:
they keep telling me my “total” is read only…what is tthat supposed to mean?

Your code so far

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

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

Your browser information:

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

Challenge: Basic JavaScript - Iterate Through an Array with a For Loop

Link to the challenge:

If you use const to declare variables, it limits what you can then do with them:

There are many cases where const is the best keyword to use, but not in this case.

If you wish to use an assignment operator on a variable once it’s declared, you’d need to declare it with let instead.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.