Hey CC Community!
I’m a first time poster and beginner on the Full Stack Engineer path, so bear with me if my question reaks of n00b.
So, I was answering a question in one of the Practice Pack for the topic: Javascript Syntax Part II: Loops (https://www.codecademy.com/practice/paths/full-stack-engineer-career-path/tracks/fscp-javascript-syntax-part-ii/modules/fecp-learn-javascript-syntax-loops).
Here is the question I was given:
What is the value that is computed by this code block?
[and the code]
const values = [1, 10, 4, 3, 15, 3, 5, 2];
let total = 100
for (let i = values.length - 2; i >= 0; i -= 2) {
let a = values[i];
total /= a;
total += 10;
}
console.log(total);
After some calculations, and as many guesses as the site allowed, I finally got the answer to the question (Spoiler Alert: 23). However, I can not for the life of me, understand why. Before this, I believed I had a good understanding of variables, ‘for’ loops/reversing ‘for’ loops, and control flow, but this single question has me questioning that belief.
If anyone has some time, can you please explain to me why the answer is what it is?
Thanks!