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 Build a Quiz Challenge – One Solution

Dennis Trinidad
Dennis Trinidad
Full Stack JavaScript Techdegree Student 759 Points

Variables Let, Const

it wasnt running when I had instead of let correctAnswers = 0 const correctAnswers = 0

why we can have const in questions but not in correctAnswers.

Would you mind to refer me to a video where is it explained

1 Answer

Bella Bradbury
.a{fill-rule:evenodd;}techdegree seal-36
Bella Bradbury
Front End Web Development Techdegree Graduate 32,790 Points

Hi Dennis!

It's a good idea to post your complete code when posting a question, this helps us to make sure that we're able to fully resolve your issue. However, I believe I can still help via context clues.

The reason that const wouldn't work in this situation is because it's a constant variable. This means that it can't be reassigned or redeclared. Think of it like the value of your birthday, it's never going to change because it's a fixed piece of information.

let will work because it's a re-assignable variable. In our birthday analogy, this would be your age. It's a piece of information that shouldn't be locked in because it will be changing.

When used properly the syntax of these two variables would look like this:

const birthday = "January 1, 2000";
let age = 0;

// my age in 2005 
age = 5;

//my age in 2017
age = 17;

See how we only declare the birthday variable once, but are able to reassign the age variable? That's the difference between let and 'const'.

There is also a third type of variable, var which is very similar to let but instead deals with the scope of the variable. Here's a comparison of the three ways to define a variable in JavaScript.

You also mentioned Treehouse videos about defining variables. Here are some of the available resources:

Happy coding!