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 Solution

Matthew Cornell
Matthew Cornell
1,304 Points

My solution

Hope you like Monty Python!

/*This is the QUIZZZ Challenge.
You must fulfill the following criteria
1. Ask at least 5 questions
2. Keep Track of the number of questions the player answers correctly
3. Deliver a final message to the player with the total number of correctly answered questions
4. Rank the player Gold (all 5 questions right) Silver (3-4 right) Bronze (1-2 right) or the LOSER (none right)
*/

//setting the scene...//
var guess = false;
var correctAnswers = 0;
var incorrectAnswers = 0;
var userName = prompt("Before you begin your quest, you must presnt your name.");
alert("All hail Sir " + userName + "!");
alert("Have you seen Monty Python and the Holy Grail? There is a scene in that movie where the valient hero's must answer soul-serching questions! You will now answer questions based on that scene. (Pssst...see https://www.youtube.com/watch?v=pWS8Mg-JWSg for some help...)");


//asking the first question and adding one to the correctAsnwer variable if correct.//      
var q1Answer = prompt("What is Sir Lancelot's Favorite Color?")
if (q1Answer.toUpperCase() === 'BLUE'){
 correctAnswers += 1;
} else {
      incorrectAnswers += 1;
}

//The next couple are the same layout for the other 4 questions//
var q2Answer = prompt("What is Sir Robin's reaction to Sir Lancelot's questions?")
if (q2Answer.toUpperCase() === "THATS EASY"){
 correctAnswers += 1;
}   else if (q2Answer.toUpperCase() === "THAT'S EASY"){
      correctAnswers += 1;
}   else {
      incorrectAnswers += 1;
}

var q3Answer = prompt("What questions did Sir Robin miss?")
if (q3Answer.toUpperCase() === 'WHAT IS THE CAPITAL OF ASSYRIA?'){
 correctAnswers += 1;
} else {
      incorrectAnswers += 1;
}


var q4Answer = prompt("What is Sir Gallahad's REAL Favorite Color?")
if (q4Answer.toUpperCase() === 'YELLOW'){
 correctAnswers += 1;
} else if((q4Answer.toUpperCase() === 'BLUE')){
    q4Answer = prompt("Check again...its hard to hear, but listen for his REAL favorite color.");
 if (q4Answer.toUpperCase() === 'YELLOW'){
 correctAnswers += 1;
}} else {
      incorrectAnswers += 1;
} 


var q5Answer = prompt("What is King Aurthur's answer to the Bridgekeeprs final question?")
if (q5Answer.toUpperCase() === 'WHAT DO YOU MEAN? AN AFRICAN OR EUROPEAN SWALLOW?'){
 correctAnswers += 1;
} else {
      incorrectAnswers += 1;
}

//Grading time! And designation of rank dependent on ranking//
if (correctAnswers === 5){
    document.write("Sir " + userName + ", you have answered " + correctAnswers + " answers correct, and " + incorrectAnswers + " answers incorrect. You have earned the Golden Crown! ALL HAIL, KING " + userName.toUpperCase() + "!");
} else if (correctAnswers === 3 || correctAnswers === 4){
     document.write("Sir " + userName + ", you have answered " + correctAnswers + " answers correct, and " + incorrectAnswers + " answers incorrect. You have earned the Silver sceptre! Well done, Sir " + userName + "!");

} else if (correctAnswers === 1 || correctAnswers === 2){
  document.write("Sir " + userName + ", you have answered " + correctAnswers + " answers correct, and " + incorrectAnswers + " answers incorrect. You have earned the bronze shovel, and you have lost your knighthood! You really should've watched the video closer, " + userName + "!");
  } else {
     document.write("Sir " + userName + ", you have answered " + correctAnswers + " answers correct, and " + incorrectAnswers + " answers incorrect. YOU ARE THE JESTER! DANCE, " + userName.toUpperCase() + " DANCE!");
  }

very cool :)

1 Answer

Great Job!