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 trialsebbe12
4,015 Pointshttps://w.trhou.se/6vsb4uoung Please take my challange and see what you think of it
Thank you dave for this challange took around 45-1hr to do but it was worth it. Just thinking and trying things out make you stronger and you see what works and not.
Here is my quiz you can take it and say what you think about it. If you are experience coder please look in the code and see if there is things that are not the best things to do.
Gl!
2 Answers
Steven Parker
231,269 PointsI notice each question has a code block like this:
if (108 === parseInt(question1)) {
var score = score + 1;
if (108 !== parseInt(question1)) {
var score = score + 0;
}
}
Notice that the 2nd "if" will never be true because it is inside the first "if", and it is testing for the opposite condition. So the 2nd "if" can be omitted entirely for that reason, and also because even if it could ever run, it does not change the score.
But if you did want to make a change on the opposite condition, like subtract a penalty, the conventional way would use an "else" statement:
if (108 == parseInt(question1)) {
var score += 1; // a more compact version of: score = score + 1
} else {
var score -= 1; // subtract one as a penalty
}
sebbe12
4,015 PointsAlright i just wanted it to say the score will be the same if they got the question wrong guess thats unecessary.
Steven Parker
231,269 PointsSteven Parker
231,269 PointsAlso, just for fun, a more compact way to do the same thing involves the ternary expression:
score += 108 == parseInt(question1) ? 1 : -1;
sebbe12
4,015 Pointssebbe12
4,015 PointsI have been wondering and haven't got a answer yet i was wondering how to type "&&" on the keyboard. I got logitech g710+ if it matters.
Want to know how to type this > &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&