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 trialJose Tommaso
5,559 PointsHey! Here's my quiz.. LF feedback :)
Hi guys! this is my solution.. thank you for your feedback!
// general knowledge quiz
var score = 0;
/*
1. Prompt the user the question.
2. Transform user input to lowercase and check if the answer is correct.
3. If user answer correctly, add 1 point to the score variable, otherwise alert that it is not the correct answer.
*/
// First Question
var question1 = prompt("First Question: Which Olympic sport takes place in a velodrome?");
if ( question1.toLowerCase() === 'cycling' ) {
score++;
alert( "That's the correct answer!!! Your score is " + score );
} else {
alert(' Incorrect answer. The correct answer is "Cycling" ');
}
// Second Question
var question2 = prompt("Second Question: Prior to joining the euro, what was the currency of Spain?");
if ( question2.toLowerCase() === 'peseta' ) {
score++;
alert( "That's the correct answer!!! Your score is " + score );
} else {
alert(' Incorrect answer. The correct answer is "Peseta" ');
}
// Third Question
var question3 = prompt("Third Question: In terms of area, what is the largest country in South America?");
if ( question3.toLowerCase() === 'brazil' ) {
score++;
alert( "That's the correct answer!!! Your score is " + score );
} else {
alert(' Incorrect answer. The correct answer is "Brazil" ');
}
// Fourth Question
var question4 = prompt("Fourth Question: Brie and Camembert are types of which food?");
if ( question4.toLowerCase() === 'cheese' ) {
score++;
alert( "That's the correct answer!!! Your score is " + score );
} else {
alert(' Incorrect answer. The correct answer is "Cheese" ');
}
// Fifth Question
var question5 = prompt("Fifth Question: Which joint connects the foot to the leg?");
if ( question5.toLowerCase() === 'ankle' ) {
score++;
alert( "That's the correct answer!!! Your score is " + score );
} else {
alert(' Incorrect answer. The correct answer is "Ankle" ');
}
/*
1. Check user score.
5 points = Gold Crown
3-4 points = Silver Crown
1-2 points = Bronze Crown
0 points = No crown
*/
if ( score === 5 ) {
alert( 'You have got ' + score + ' answers correctly. You won the Gold crown! Congratulations.' );
} else if ( score >= 3 ) {
alert('You have got ' + score + ' answers correctly. You won the Silver crown! Congratulations.');
} else if ( score >= 1 ) {
alert('You have got ' + score + ' answers correctly. You won the Bronze crown! Congratulations.');
} else {
alert('You did not answer any question correctly. =(');
}
1 Answer
Piotr Manczak
Front End Web Development Techdegree Graduate 29,367 PointsPure beauty. Simple and effective.
Jose Tommaso
5,559 PointsJose Tommaso
5,559 PointsPiotr Manczak Thank you!