JavaScript JavaScript Basics Making Decisions in Your Code with Conditional Statements The Conditional Challenge Solution

guil's quiz app is very had for me so i make my own quiz app

guil is very smart but his quiz app is veryx difficult for me so i make my own quiz app guil's quiz app only record of the scor the player mades but he doesnt look at the lossing points so i make my own if anyone also facing that issue then look at mine this is a lot simpler

let rank = 0; let ruby= prompt("what is a programming langauage which is also a gem ?"); let python = prompt("what is aprogramming language which is also a snake ?"); let css = prompt("what is a programming langauge to style web pages ?"); let html = prompt("what is a programming langauge to build web pages ?"); let javascript = prompt("what is a programming language to add ineractivity to web pages ?"); let correctGuess; let gold; let silver; let bronze; let nocrown;

if(ruby==="ruby"){ rank += 1; }else if(ruby !== "ruby"){ rank = 0; }

if(python==="python"){ rank += 1; }else if(python !== "python"){ rank = rank; }

if(css==="css"){ rank += 1; }else if(css !== "css"){ rank = rank; }

if(html==="html"){ rank += 1; }else if(html !== html){ rank = rank; }

if(javascript==="javascript"){ rank += 1; }else if(javascript !== "javascript"){ rank = rank; }

if(rank==0){ nocrown = "Nocrown"; }else if(rank==1 || rank==2){ bronze = "Bronze"; }else if( rank == 3 || rank == 4){ silver = "Silver"; }else if( rank == 5 ){ gold = "Gold" }

// 3. Select the <main> HTML element let main = document.querySelector('main'); main.innerHTML= <p>Your ${rank} answers are correct. That's why you won ${nocrown||bronze||silver||gold}</p> ;

1 Answer

Steven Parker
Steven Parker
207,988 Points

You can still simplify this even more, for example:

if (python === "python") {
  rank += 1;
//} else if (python !== "python") {
//  rank = rank;
}

The lines shown commented out can be omitted entirely since "rank = rank" doesn't change anything.

But you mentioned keeping track of points lost, so you might want to do something like this:

if (python === "python") {
  rank += 1;
} else {      // another "if" not needed
  lost += 1;  // keep count of missed questions
}

And when posting code to the forum, use Markdown formatting to preserve the appearance and optionally add syntax coloring (as shown here).

hey steven did you encouter any error while opening any page on mozilla developer network

Steven Parker
Steven Parker
207,988 Points

I didn't use it while composing this answer, but I do use MDN frequently and have had no problems with it.