Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Arrays Multidimensional Arrays Improve the Quiz – One Solution

let or const for lines 10-12

on line 12, you use let for correct answers, I'm assuming because the value changes after each correct answer. but for lines 10 and 11, you use const even though they change too.

Do you use const because it's the same array but just being added to? vs, the let it changes the value completely?

1 Answer

Hi Marian!

Affirmative Earthling!?! LOL J/K, of course!?!

BTW, if you haven't seen Resident Alien on the Sci-Fi channel it's hilarious! (SOOOOOOO funny!). You can watch it On Demand or on the website (as well as on the Sci-Fi channel).

But, yes, you are correct.

An array declared as a const has all the behaviors/qualities of an array, but you can't change its type (to an int or string or anything else - it can only be the original declared array).

const cars = ["Saab", "Volvo", "BMW"];
cars.push("Fiat"); // No error
cars = 2; // Uncaught TypeError: Assignment to constant variable.

With let, you can, but with limited (and protective) scope.

With var, it's anything goes, which is why they came up with let and const, for some variable usage safeguards.

More info:

https://www.freecodecamp.org/news/var-let-and-const-whats-the-difference/

https://www.tutorialspoint.com/es6/es6_variables.htm

I hope that helps.

Stay safe and happy coding!