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

Andrew Walters
Andrew Walters
8,876 Points

Could you help me with some feedback?

Hey guys! New coder here, took me a while to figure this one out (kept getting weird errors when refreshing while my code was right, a simply close the preview and reopen the preview solved it weirdly enough...) looking for some feedback. Took me a while to get and still got some ways to go (I'm curious how one can answer a question and have the program ignore grammatical characters like commas or perhaps even the order of the answers). Anyways, sorry for the long post! I hope you enjoy!

var correctAnswer = 0;
var addition = prompt("What is 1000+1000?");
if (parseInt(addition) === 2000) {
  correctAnswer += 1;
  alert("You're right! You've answered " + correctAnswer + " questions correctly!");
} else {
  alert("Sorry, you answered incorrectly.");
}


var color = prompt("What are the three primary colors in alphabetical order?");
if(color.toLowerCase() === "blue, red, yellow") {
  correctAnswer +=  1;
  alert("You're right! You've answered " + correctAnswer + " questions correctly!");
} else {
  alert("Sorry, you answered incorrectly.");
}


var tweet = prompt("What programming language was Twitter built in?");
if (tweet.toLowerCase() === 'ruby') {
  correctAnswer += 1;
  alert("You're right! You've answered " + correctAnswer + " questions correctly!");
} else {
  alert("Sorry, you answered incorrectly.");
}


var multiply = prompt("What is 10 x 15?");
if (parseInt(multiply) === 150) {
  correctAnswer += 1;
  alert("You're right! You've answered " + correctAnswer + " questions correctly!");
} else {
  alert("Sorry, you answered incorrectly.");
}


var fonts = prompt("What is a browser's default font-size in pixels?");
if (parseInt(fonts) === 16) {
  correctAnswer += 1;
  alert("You're right! You've answered " + correctAnswer + " questions correctly!");
} else {
  alert("Sorry, you answered incorrectly.");
}

alert("You answered " + correctAnswer + " out of 5 questions correctly!");
var crown;
if(correctAnswer === 5) {
  document.write("<p>Congratulations! You've earned a Gold Crown!</p>");
} else if(correctAnswer <= 4 && 3<= correctAnswer) {
  document.write("<p>Congratulations! You've earned a Silver Crown!</p>");
} else if(correctAnswer <= 2 && 1<= correctAnswer) {
  document.write("<p>Congratulations! You've earned a Bronze Crown!</p>");
} else {
  document.write("<p>Sorry, you did not earn a crown.</p>");
}

1 Answer

Gary Calhoun
Gary Calhoun
10,317 Points

Hi its working good for me.! Good job! Also to make it easier to see when you post code you can use the markdown cheat sheet in order to show it properly, for example the javascript is three tick marks which is next to the 1 key and then type javascript in lowercase then to end just use three tick marks like this

//```javascript
var javascript = "JavaScript";
console.log(javascript);
//```
Andrew Walters
Andrew Walters
8,876 Points

Sounds great! Thanks for your feedback and for the info! So when I'm making a post, just use the markdown so that it will display properly? Thanks again!