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 trialYemaya Re
Courses Plus Student 1,922 PointsUnsure how to alert user properly
Once all 5 questions run, If user gets one question wrong, it proceeds to give all of the wrong alert messages. I'm unsure how to alert the user properly of questions missed. All any suggestions on simplifying my code would be appreciated. Thanks for any feedback in advance.
//Healed by the Bush game asks player 5 questions, then ranks player in the end
var totalCorrect ='';
var answerOne = prompt('What aromatic vegetable can be used to prevent and even REVERSE heart disease? It\'s also an effective vampire deterrent.');
var answerTwo = prompt('What sticky substance has been used for centuries to treat an astonishing number of ailments: From colds to allergies to diabetes prevention? If you attempt to take this from Winnie the Pooh, he will eat you.');
var answerThree = prompt('This common citrus fruit fights cancer, prevents wrinkles and is excellent for liver detoxification. If you suck on this, you\'ll make a sour pucker face.');
var answerFour = prompt('This potent anit-inflammatory has a proven track record over 2,000 years old in traditional Chinese medicine and is more effective than otc pain meds at relieving cramps(Yes ladies!). Red-heads are sometimes called this instead.');
var answerFive = prompt('Ancient civilizations used this powerful spice as a brain tonic. It eliminates mental fatigue, alieviates anxiety and depression and improves concentration. Rhymes with "hut egg"');
if (answerOne.toUpperCase() === 'GARLIC') {
totalCorrect = 1;
} else {
totalCorrect < 5;
alert('Sorry try again');
}
if (totalCorrect === 1 && answerTwo.toUpperCase() === 'HONEY') {
totalCorrect = 2;
} else {
totalCorrect < 4;
alert('Answer no good');
}
if (totalCorrect === 2 && answerThree.toUpperCase() === 'LEMON') {
totalCorrect = 3;
} else {
totalCorrect < 3;
alert('Sorry, that\'s incorrect');
}
if (totalCorrect === 3 && answerFour.toUpperCase() === 'GINGER') {
totalCorrect = 4;
} else {
totalCorrect < 2;
alert('Maybe try google for a clue?');
}
if (totalCorrect === 4 && answerFive.toUpperCase() === 'NUTMEG') {
totalCorrect = 5;
} else {
totalCorrect < 1;
alert('Wrong. And I was worried this quiz was too easy...');
}
if (totalCorrect === 5) {
alert('You aced every question like a BOSS.');
document.write('<h2>Congratulations! You\'ve earned the Gold Crown and are well on your way to becoming a Healer by the Bush!</h2>');
}
else if (totalCorrect >= 3) {
document.write('<h2>Getting closer! You\'ve earned the Silver Crown.</h2>');
}
else if (totalCorrect >= 1) {
document.write('<h2>A little more studying will do you good. You\'ve earned the Bronze Crown.</h2>');
}
else {
totalCorrect === 0
alert('Aye aye aye...You missed every question.');
document.write('<h2>As said in the 20th century, hit the books! You\'ll do better next time.</h2>');
}
1 Answer
Steven Parker
231,236 PointsI notice that your logic will only score a correct answer if every answer before it was also right. Is that intentional?
Also, your answers come after all 5 questions because that's how your program is structured. If you wanted to issue the answer directly after each question, you would need to move the answer logic so that it immediately follows the prompt statement that goes with it.
Yemaya Re
Courses Plus Student 1,922 PointsYemaya Re
Courses Plus Student 1,922 PointsHey, honestly I have racked my brain trying to complete this challenge. This is the 3rd rendition of it. And to answer your first question, Yes... I thought that was right anyway. And you say re work my logic so it comes after each question.... Did I not do that? by using 'else' if the answer is wrong, then I placed the incorrect alert message there. I thought I had some sort of idea how to complete this but the more I coded and it wasn't working correctly, the more lost I feel! I haven't seen the solution video yet...
Steven Parker
231,236 PointsSteven Parker
231,236 PointsWatch the solution video to see how the instructor did it. You'll see that he doesn't put all the prompt statements together, but mixes them with testing the answers.