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

sebbe12
sebbe12
4,015 Points

https://w.trhou.se/6vsb4uoung Please take my challange and see what you think of it

https://w.trhou.se/6vsb4uoung

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
Steven Parker
231,269 Points

I 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
}
Steven Parker
Steven Parker
231,269 Points

Also, just for fun, a more compact way to do the same thing involves the ternary expression:

score += 108 == parseInt(question1) ? 1 : -1;
sebbe12
sebbe12
4,015 Points

I 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 > &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

sebbe12
sebbe12
4,015 Points

Alright i just wanted it to say the score will be the same if they got the question wrong guess thats unecessary.