Iterating through an array - PLease Help

would someone PLEASE give me the solution to
https://csx.codesmith.io/units/precourse-part-2/challenge-for-loops-calculating-array-elements

I feel like an idiot! thanks

Whoops. Thank you Randell. I completely forgot that I was accessing it through a login. My sincere mistake. I see why this looks bad lol.

I am indeed a member of freecodecamp as well… Trying many online resources to see what sticks… what I should learn first, etc…

I will post the actual challenge if that’s ok - I will make sure to not point to external stuff from now on!

Please help me with this guys…really simple why is my brain freezing??
CHALLENGE: You are given an array of five numbers called increaseByTwo . Use a for loop to iterate through the array and increase each number by two.

const increaseByTwo = [1, 2, 3, 4, 5];
// ADD CODE HERE

// Uncomment the line below to check your work!
// console.log(increaseByTwo); // -> should print [3, 4, 5, 6, 7];

I always get stuck with loops at first. Dunno why.

I know that arrays use zero based indexing. So the first item in an array is ā€œ0ā€, the second ā€œ1ā€ etc. ie:

let friends = [ā€˜George’, ā€˜Thai’, ā€˜Brandon’];
console.log(friends[2]); // should log: ā€˜Brandon’

const increaseByTwo = [1, 2, 3, 4, 5];
// ADD CODE HERE
let i = increaseByTwo.length

for (let i = 0 ; i < 5; i++) {
//not sure what to put here
}

// Uncomment the line below to check your work!
// console.log(increaseByTwo); // -> should print [3, 4, 5, 6, 7]; (for me it still prints 1,2,3,4,5)

Completly STUCK on this…i don’t know how to modify(i.e.assign number 10 to 2nd index)

other than ā€œpushā€ new values into a brand new array…???

if you can give me the solution i’d appreciate it…

(Thank G-d I only pass along work to coders for a living!!!)

When you are iterating through an array you are looping through its index. To get the index of an array you use square brackets like array[0]. So in your case you want to iterate increaseByTwo[i]. This is how you get the index but because you want to reassign the value at the given index you must reassign increaseByTwo[i] = increaseByTwo[i] + 2 or increaseByTwo[i] += 2

Also instead of declaring ā€œiā€ you should just initialize in the loop, because the length of your array is 5 now but what if the length was greater than 5.

for(let i = 0; i < increaseByTwo.length; i++) {}