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

Kevin Bakke
Kevin Bakke
2,058 Points

Just looking for feedback. Thanks!

//This is the starting score
var score = 0

/*Start to questions
  1. if question is correct, add 1 to score
  2. if question is wrong, add 0 to score
*/
var question1 = prompt('What is the operator sign for the Or Operator?')
if ( question1 === '||' ) {
  score += 1;
} else {
  score += 0;
}
var question2 = prompt('What is the operator sign for Equal to but not Strict?')
if ( question2 === '==' ) {
  score += 1;
} else {
  score += 0;
}

var question3 = prompt('Is JavaScript the same as Java?')
if ( question3.toUpperCase() === 'NO' ) {
  score += 1;
} else {
  score += 0;
}

var question4 = prompt('What is the Style language of a Webpage layout?')
if ( question4.toUpperCase() === 'CSS' ) {
  score += 1;
} else {
  score += 0;
}

var question5 = prompt('How do you convert a string in to a floating number?')
if ( question5 === 'parseFloat()' ) {
  score += 1;
} else {
  score += 0;
}
/*Depending on the score
  1. score is 5, player gets a gold crown
  2. score is 3-4, player gets a silver crown
  3. score is 1-2, player gets a bronze crown
  4. score is 0, no crown is given
*/
if (score === 5 ) {
  document.write('Your score is ' + score + ' out of 5.  Well done! You get a gold crown!');
} else if ( score <= 4 && score >= 3 ) {
    document.write('Your score is ' + score + ' our of 5. Well done! You get a silver crown!');
} else if ( score <= 2 && score >= 1 ) {
  document.write('Your score is ' + score + ' our of 5. You get a bronze crown!');
} else {
  document.write('Sorry! You get no crown. Better luck next time!');
}

1 Answer

Steven Parker
Steven Parker
231,248 Points

Working code = good job. :+1: And I can see that this code would work if it was formatted.

Even if they're not required at the end of a line, it's a "best practice" to put semicolons at the end of each statement. Since they weren't there, when the lack of formatting folded the lines above, the code became non-functional.

And to prevent line folding and other undesirable changes, always use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area. :arrow_heading_down:   Or watch this video on code formatting.

Kevin Bakke
Kevin Bakke
2,058 Points

Great! Thank you, Steven! I will be sure to reference the Markdown Cheatsheet for future posts.

Steven Parker
Steven Parker
231,248 Points

For practice, you might edit this question so the code is formatted for the benefit of any students reading it later.