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
Alex Johnson
6,319 PointsHey there, I'd be really grateful if anyone has some time to give me some feedback on the Conditional Challenge :)
// say hello and welcome
alert('Welcome to my quiz, there are some general knowledge questions and maths questions, Have Fun!');
// variable to contain score starts at 0
var score = 0;
// answer variables start as false
var answer1 = false; var answer2 = false; var answer3 = false; var answer4 = false; var answer5 = false;
// question 1
var question1 = prompt('Which Country is Munich Situated in?');
if ( question1.toUpperCase() === 'GERMANY') { answer1 = true;
if (answer1 === true) {
score += 1;
}
} else { score +=0; }
//question 2
var question2 = prompt('Which French Classical Composer wrote a series of works named "Reveries"?');
if ( question2.toUpperCase() === 'CLAUDE DEBUSSY' || question2.toUpperCase() === 'DEBUSSY' ) { answer2 = true;
if ( answer2 === true ) {
score += 1;
}
} else { score +=0; }
//question 3
var question3 = prompt('What is the total of 2020 and 0202 ?');
if ( parseFloat(question3) === 2222 ) { answer3 = true;
if (answer3) {
score += 1;
}
} else { score = 0; }
// question 4
var question4 = prompt('If I have 12 eggs and you buy 3 loafs of bread how many items do you have?');
if ( parseFloat(question4) === 3 ) { answer4 = true;
if (answer4) {
score += 1;
}
} else { score += 0; }
// question 5
var question5 = prompt('Whats is the name of the tallest building in London');
if ( question5.toUpperCase() === 'THE SHARD' || question5.toUpperCase() === 'SHARD' ) { answer5 = true;
if ( answer5 === true ) {
score += 1;
}
} else { score +=0; }
// message - if else statment to help with Grammar
var message = '';
if ( score === 1) { message += '<p>Thanks for playing, you got ' + score + ' point <br>'; } else { message += '<p>Thanks for playing, you got ' + score + ' points <br>'; }
// scoring system
if ( score === 5 ) {
message += 'EXCELLENT!!<br>You have Won the <strong>Gold Crown!</strong></p>';
} else if ( score === 3 || score === 4 ) {
message += '<strong>You got the Silver Crown!</strong> Well done!</p>'
} else if ( score === 1 || score === 2 ) {
message += '<strong>You got the Bronze Crown!</strong> Well done!</p>'
} else if ( score === 0 ) {
message += 'No Crown for you!</p>'
} else {
}
document.write(message);
1 Answer
Alex Johnson
6,319 PointsThanks Steven, I'll check that out! Cheers
Steven Parker
243,215 PointsSteven Parker
243,215 PointsWhen posting code, use "Markdown" formatting to preserve special characters and indenting. There's a pop-up "cheatsheet" below, or you can watch this video on code formatting.