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

Can you guys give me your feedback for this challenge? I know how bad I suck, so I expect only criticism :). Thank you

var countAnswer = 0;

var answer = prompt ("What is 2+ 2?");
if (answer === "4") {
  countAnswer += 1;
} else {
  document.write("Wrong");
}

var answer = prompt ("What does US stand for?");
if (answer === "United States") {
  countAnswer += 1;
} else {
  document.write("Wrong");
}


var answer = prompt ("What are the biggest movie Awards?");
if (answer === "Oscars") {
  countAnswer += 1;
} else {
  document.write("Wrong");
}


var answer = prompt ("Who is the first name of the main character from the Tv show, The sopranos?");
if (answer === "Tony") {
  countAnswer += 1;
} else {
  document.write("Wrong");
}


var answer = prompt ("What is the name of the largest country in the world?");
if (answer === "Russia") {
  countAnswer += 1;
} else {
  document.write("Wrong");
}

document.write ("You have answered correctly to " + countAnswer + " questions");

if(countAnswer === 5) {
  alert("The Gold is yours!!!");
} else if (countAnswer < 5 && countAnswer > 2) {
  alert("The Silver is yours!!");
} else if (countAnswer < 3 && countAnswer < 0) {
  alert ("You have won the bronze");
} else {
 alert ("Try harder");
}

4 Answers

Steven Parker
Steven Parker
243,656 Points

It looks like you had a problem with the blockquoting, and some of your code didn't come through making it hard to do an evaluation.

But assuming only a few bits are missing, I only have a couple of comments:

  • you ask questions with prompts and your final feedback is done with alerts, but feedback on individual questions and the correct answer count are written to the document
  • you provide "Wrong" feedback on individual questions but not "Right/Correct/Good"

Other than that, it seemed pretty well done. Not too sucky after all. :smirk:

It's coming along nicely. I've separated out your code a bit and added some comments to help break it up and make it more readable, with some suggestions in appropriate places. Remember to spread your code so you can easily see where things can be improved.

// Stores the total number of correct answers, increase by 1 for each correct answer
var countAnswer = 0;

// Question 1
var answer = prompt ("What is 2+ 2?"); 
if (answer === "4") {
  countAnswer += 1; 
  // Maybe add a document.write("Correct! ") for each correct one?
} else { 
  document.write("Wrong"); // Add a space after Wrong so that you wont end up with wrongwrongwrong... etc
} 

// Question 2
var answer = prompt ("What does US stand for?"); //No need for var re-declaring on answer variable.
if (answer === "United States") { //what if someone types 'united states'?
  countAnswer += 1; 
  // Maybe add a document.write("Correct! ") for each correct one?
} else { 
  document.write("Wrong"); 
}

// Question 3
var answer = prompt ("What are the biggest movie Awards?"); 
if (answer === "Oscars") { //what if someone types 'oscars'?
  countAnswer += 1; 
  // Maybe add a document.write("Correct! ") for each correct one?
} else { 
  document.write("Wrong"); 
}

// Question 4
var answer = prompt ("Who is the first name of the main character from the Tv show, The sopranos?"); 
if (answer === "Tony") { //what if someone types 'tony'?
  countAnswer += 1; 
  // Maybe add a document.write("Correct! ") for each correct one?
} else { 
  document.write("Wrong"); 
}

// Question 5
var answer = prompt ("What is the name of the largest country in the world?"); 
if (answer === "Russia") { //what if someone types 'russia'?
  countAnswer += 1; 
  // Maybe add a document.write("Correct! ") for each correct one?
} else { 
  document.write("Wrong"); 
}

// Getting the total score and deciding which crown the user wins
document.write ("You have answered correctly to " + countAnswer + " questions");

if(countAnswer === 5) { 
  alert("The Gold is yours!!!"); 
} else if (countAnswer 2) {  // This conditional won't do what you expect and probably cause a syntax error
  alert("The Silver is yours!!"); 
} else if (countAnswer  //This will cause a syntax error, keep a lookout for un-paired brackets.
  alert ("You have won the bronze"); 
} else { 
  alert ("Try harder"); 
}
Steven Parker
Steven Parker
243,656 Points

I'm pretty sure the missing comparisons and brackets were a result of not blockquoting. The actual code probably runs fine.

Thanks a lot for the feedback and the advice

Interesting, never seen blockquoting deleting script but I guess it can happen (although I am a newbie on Treehouse so not sure how their printing works).

Steven Parker : Yes, the code runs but, anyway thank you for taking the time to give me your feedback. I really appreciate it. PS: no block quoting indeed. Lesson learned :)

Steven Parker
Steven Parker
243,656 Points

For future reference, you blockquote javascript like this... first skip a blank line, and then:

```js
//Your code goes here
```

Those little marks are accents (aka "backticks")

Steven Parker Thanks! I have edited the code with blockquote.