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
Cedric M. MOUSSOUNDA
4,377 PointsThe Conditional Challenge - What I did first.
This is how I complete this challenge. There is much redundancy and it can be improved with the straightforward solution of Guil.
/* The Conditional Challenge use conditional statements to build a multiple question quiz. */
// 1. Ask at least five questions // 2. Keep track of the number of questions the user answered correctly // 3. Provide a final message after the quiz letting know the number of questions he or she got right /* 4. Rank the player. If the player answered all five correctly, give that player the gold crown: 3-4 is a silver crown; 1-2 correct answer is a bronze crown; 0 correct answer is no crown at all */
//quiz begins, no answers correct var questions = 0;
var correctGuess = 'CEDRIC'; var questionsLeft = '[' + questions + ' correct answer]'; var answer = prompt('What\'s your name?');
if (answer.toUpperCase() === correctGuess) { questions += 1; questionsLeft = '[' + questions + ' questions answered correctly out of 5]'; alert('You\'re doing great! ' + questionsLeft); } else { alert('Sorry. Try again.'); }
correctGuess = 42; var answer2 = prompt('How old are you?');
if (parseInt(answer2) === correctGuess) { questions += 1; questionsLeft = '[' + questions + ' questions answered correctly out of 5]'; alert('You\'re doing great! ' + questionsLeft); } else { alert('Sorry. Try again.'); }
correctGuess = GABON; var answer3 = prompt('Where do you live?');
if (answer3.toUpperCase) === correctGuess) { questions += 1; questionsLeft = '[' + questions + ' questions answered correctly out of 5]'; alert('You\'re doing great! ' + questionsLeft); } else { alert('Sorry. Try again.'); }
correctGuess = 'WEB DEVELOPER'; var answer4 = prompt('What is your job?');
if (answer4.toUpperCase() === correctGuess) { questions += 1; questionsLeft = '[' + questions + ' questions answered correctly out of 5]'; alert('You\'re doing great! ' + questionsLeft); } else { alert('Sorry. Try again.'); }
correctGuess = 'NO!' var answer5 = prompt('Do you like cheese?');
if (answer5.toUpperCase() === correctGuess) { questions += 1; questionsLeft = '[' + questions + ' questions answered correctly out of 5]'; alert('You\'re doing great! ' + questionsLeft); } else { alert('Sorry. Try again.'); }
if (questions === 5 && questions != 0) { alert('Congratulations! You got the Gold crown!'); } else if (questions === 3 || questions === 4) { alert('You got the silver crown!'); } else if (questions === 1 || questions === 2) { alert('You got the bronze crown'); } else { alert('Sorry. Let\'s try again!'); }
Cedric M. MOUSSOUNDA
4,377 PointsHi Steve, it's just a comment on what I did to take on this challenge. I'm very impressed by your profile!
Steven Parker
243,656 PointsSteven Parker
243,656 PointsAre you asking a question?