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 Basics (Retired) Making Decisions with Conditional Statements The Conditional Challenge Solution

For the quiz, is it ok to use correct++ for each right answer instead of correct + 1?

Worked ok in my quiz, but wasn't sure which would be preferred in this case.

1 Answer

Hey Clay, if you tried it and it worked, then I guess it's fine. One thing to point out about the ++ method of incrementing values up, is that where you place the ++ changes what the value is at the moment it's used:

var a = 1;
var b = a + 1;
console.log(b); // b is 2, as you'd expect.

var c = 1;
var d = c++;
console.log(d); // d is actually 1, because c only became 2 AFTER it was assigned to d.

var e = 1;
var f = ++e;
console.log(f); // f is 2, because e became 2 and THEN was assigned to f.

The difference is where the ++ is placed: after the variable means it gets incremented after doing whatever it's doing there (in the case above, being assigned to the new variable). Before the variable means it gets incremented before doing whatever it's doing there.

Yes, it worked, but I can see how placement could lead to unforeseen results. Thank you for this very helpful answer!