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 trialRui Neves
3,393 Points// Quiz wiht 5 questions!
//Question n.1
alert("Welcome to the QUIZ SHOW! Please answer in English"); alert("If you get all the answers right you will get a GOLD CROWN, between 3-4 You get a SILVER CRONW, 1-2 a BRONZE CROWN and NO CROWN for the loosers!") var questions = 5; var questionsLeft = " [" + questions + " questions left]"; var score = 0; var scoreScreen = "<h2>YOUR SCORE IS " + score +"!!!"; // Player score!
var question1 = prompt("What is the Christmas day?" + questionsLeft);//Question asked + How many questions left. questions -=1;
if (question1 === "25.12" || question1.toUpperCase() === "25 DECEMBER" || question1.toUpperCase() === "25 OF DECEMBER") { //Correct answers. question1 = true; score += 1; console.log(score); alert("You are right! You got 1 Point!" ); } else { question1 = false; alert("Sorry, you are wrong."); } //Question validation / Score. if (question1) { alert("Well Done you are one step closer to the Gold Crown! ") // Print the score out // document.write("<h2>YOUR SCORE IS " + score +"!!!"); console.log(scoreScreen) } else { score += 0; alert(" Sorry... keep trying! You still aiming to the SILVER CROWN! "); } console.log(questions);
var question2 = prompt("What is the first day od the week?" + questionsLeft);//Question asked + How many questions left. questions -=1 ;
if ( question2.toUpperCase() === "MONDAY") { //Correct answers. question2 = true; score += 1; console.log(score); alert("You are right! You got 1 Point!" ); } else { question2 = false; alert("Sorry, you are wrong."); } //Question validation / Score. if (question2) { alert("Well Done you are one step closer to the Gold Crown! ") // Print the score out // document.write("<h2>YOUR SCORE IS " + score +"!!!"); console.log(scoreScreen) } else { score += 0; alert(" Sorry... keep trying! You still aiming to the SILVER CROWN! "); } console.log(questions);
var question3 = prompt("What is the name of Apple Phone?" + questionsLeft);//Question asked + How many questions left. questions -=1;
if ( question3.toUpperCase() === "IPHONE") { //Correct answers. question3 = true; score += 1; console.log(score); alert("You are right! You got 1 Point!" ); } else { question3 = false; alert("Sorry, you are wrong."); } //Question validation / Score. if (question3) { alert("Well Done you are one step closer to the Gold Crown! ") // Print the score out // document.write("<h2>YOUR SCORE IS " + score +"!!!"); console.log(scoreScreen) } else { score += 0; alert(" Sorry... keep trying! You still aiming to the SILVER CROWN! "); } console.log(questions);
var question4 = prompt("What is the name of the first dog going into space?" + questionsLeft);//Question asked + How many questions left. questions -=1;
if ( question4.toUpperCase() === "LAZZIE" || question4.toUpperCase() === "LAZIE") { //Correct answers. question4 = true; score += 1; console.log(score); alert("You are right! You got 1 Point!" ); } else { question4 = false; alert("Sorry, you are wrong."); } //Question validation / Score. if (question4) { alert("Well Done you are one step closer to the Gold Crown! ") // Print the score out // document.write("<h2>YOUR SCORE IS " + score +"!!!"); console.log(scoreScreen) } else { score += 0; alert(" Sorry... keep trying! You still aiming to the BRONZE CROWN! "); } console.log(questions);
var question4 = prompt("How many questions dido you answer until now?" + questionsLeft);//Question asked + How many questions left. questions -=1;
if ( question4.toUpperCase() === "FIVE" || question4.toUpperCase() === "5") { //Correct answers. question5 = true; score += 1; console.log(score); alert("You are right! You got 1 Point!" ); } else { question5 = false; alert("Sorry, you are wrong."); } //Question validation / Score. if (score === 5) { alert("Well Done you WON THE GOLDEN CROWN!! ") // Print the score out // document.write("<h2>YOUR SCORE IS " + score +"!!!"); console.log(scoreScreen) }else if( score >= 3) { alert("Well Done you WON THE SILVER CROWN!!") }else if(score >= 1){ alert("Well Done you WON THE BRONZE CROWN!! ") }else{ score += 0; alert(" Sorry... But you failed all the answers... "); } console.log(questions);
The snapshot was giving an error :/
2 Answers
Doron Geyer
Full Stack JavaScript Techdegree Student 13,897 Pointsalso on a side note try to make it a bit easier to read in the way you've created your layout. You should ideally not have your comments inside the code blocks but rather above or between your lines of code. for example :
//write a simple quiz application, it needs to ask at least 5 questions = done
//keep track of the number of correctly answered questions= done
//provide a message letting the user know how many questions they got right.= done
//rank the payer 1-2 bronze 3-4 silver 5 gold
var question1 = 'Which programming language is named after a snake';
var question2 = 'Which programming language is named after a gemstone';
var question3 = 'Which programming language is named after a coffee';
var question4 = 'Which programming language is primarily used for web design';
var question5 = 'Which programming language is primarily used for executable programs it ends in ++';
var correctAnswers = 0;
var answer = prompt(question1);
if (answer.toUpperCase() === 'PYTHON'){
correctAnswers += 1
}
var answer = prompt(question2);
if (answer.toUpperCase() === 'RUBY'){
correctAnswers += 1
}
var answer = prompt(question3);
if (answer.toUpperCase() === 'JAVA'){
correctAnswers += 1
}
var answer = prompt(question4);
if (answer.toUpperCase() === 'JAVASCRIPT'){
correctAnswers += 1
}
var answer = prompt(question5);
if (answer.toUpperCase() === 'C++'){
correctAnswers += 1
}
// logging out to console to make sure answer numbers are correct.
console.log(correctAnswers);
// working out award level and creating an alert
if(correctAnswers <= 2 ) {
alert('you got a bronze medal');
}else if ( correctAnswers >2 && correctAnswers <= 4){
alert ('you got a silver medal');
} else {
alert('you got a Gold medal!');
}
Doron Geyer
Full Stack JavaScript Techdegree Student 13,897 PointsRui Neves you may want to use the markdown cheatsheet to make your posts more readable. I have done this here below so you can see what a difference it makes.
// Quiz wiht 5 questions!
//Question n.1
alert("Welcome to the QUIZ SHOW! Please answer in English"); alert("If you get all the answers right you will get a GOLD CROWN, between 3-4 You get a SILVER CRONW, 1-2 a BRONZE CROWN and NO CROWN for the loosers!") var questions = 5; var questionsLeft = " [" + questions + " questions left]"; var score = 0; var scoreScreen = "<h2>YOUR SCORE IS " + score +"!!!"; // Player score!
var question1 = prompt("What is the Christmas day?" + questionsLeft);//Question asked + How many questions left. questions -=1;
if (question1 === "25.12" || question1.toUpperCase() === "25 DECEMBER" || question1.toUpperCase() === "25 OF DECEMBER") { //Correct answers. question1 = true; score += 1; console.log(score); alert("You are right! You got 1 Point!" ); } else { question1 = false; alert("Sorry, you are wrong."); } //Question validation / Score. if (question1) { alert("Well Done you are one step closer to the Gold Crown! ") // Print the score out // document.write("<h2>YOUR SCORE IS " + score +"!!!"); console.log(scoreScreen) } else { score += 0; alert(" Sorry... keep trying! You still aiming to the SILVER CROWN! "); } console.log(questions);
var question2 = prompt("What is the first day od the week?" + questionsLeft);//Question asked + How many questions left. questions -=1 ;
if ( question2.toUpperCase() === "MONDAY") { //Correct answers. question2 = true; score += 1; console.log(score); alert("You are right! You got 1 Point!" ); } else { question2 = false; alert("Sorry, you are wrong."); } //Question validation / Score. if (question2) { alert("Well Done you are one step closer to the Gold Crown! ") // Print the score out // document.write("<h2>YOUR SCORE IS " + score +"!!!"); console.log(scoreScreen) } else { score += 0; alert(" Sorry... keep trying! You still aiming to the SILVER CROWN! "); } console.log(questions);
var question3 = prompt("What is the name of Apple Phone?" + questionsLeft);//Question asked + How many questions left. questions -=1;
if ( question3.toUpperCase() === "IPHONE") { //Correct answers. question3 = true; score += 1; console.log(score); alert("You are right! You got 1 Point!" ); } else { question3 = false; alert("Sorry, you are wrong."); } //Question validation / Score. if (question3) { alert("Well Done you are one step closer to the Gold Crown! ") // Print the score out // document.write("<h2>YOUR SCORE IS " + score +"!!!"); console.log(scoreScreen) } else { score += 0; alert(" Sorry... keep trying! You still aiming to the SILVER CROWN! "); } console.log(questions);
var question4 = prompt("What is the name of the first dog going into space?" + questionsLeft);//Question asked + How many questions left. questions -=1;
if ( question4.toUpperCase() === "LAZZIE" || question4.toUpperCase() === "LAZIE") { //Correct answers. question4 = true; score += 1; console.log(score); alert("You are right! You got 1 Point!" ); } else { question4 = false; alert("Sorry, you are wrong."); } //Question validation / Score. if (question4) { alert("Well Done you are one step closer to the Gold Crown! ") // Print the score out // document.write("<h2>YOUR SCORE IS " + score +"!!!"); console.log(scoreScreen) } else { score += 0; alert(" Sorry... keep trying! You still aiming to the BRONZE CROWN! "); } console.log(questions);
var question4 = prompt("How many questions dido you answer until now?" + questionsLeft);//Question asked + How many questions left. questions -=1;
if ( question4.toUpperCase() === "FIVE" || question4.toUpperCase() === "5") { //Correct answers. question5 = true; score += 1; console.log(score); alert("You are right! You got 1 Point!" ); } else { question5 = false; alert("Sorry, you are wrong."); } //Question validation / Score. if (score === 5) { alert("Well Done you WON THE GOLDEN CROWN!! ") // Print the score out // document.write("<h2>YOUR SCORE IS " + score +"!!!"); console.log(scoreScreen) }else if( score >= 3) { alert("Well Done you WON THE SILVER CROWN!!") }else if(score >= 1){ alert("Well Done you WON THE BRONZE CROWN!! ") }else{ score += 0; alert(" Sorry... But you failed all the answers... "); } console.log(questions);
The snapshot was giving an error :/
KRIS NIKOLAISEN
54,971 PointsKRIS NIKOLAISEN
54,971 PointsIf you want to share a workspace you will need to create a snapshot. It is the camera icon in the upper right corner.