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

Lunnette Lucas
Lunnette Lucas
2,091 Points

QUIZ HELLLLPP!! I'm stuck. What am I missing?

var numberOfQuestions = 5;
var score = 0;
var correct = false;
/* var Q1 = prompt("What's my name?");
var Q2 = prompt("How many days are in a week?") ;
var Q3 = prompt("Where is liberty statue?") ;
var Q4 = prompt("Who is the current president?") ;
var Q5 = prompt("ARE YOU NOT ENTERTAINED?!") ;
var Q1 = prompt("What's my name?");*/
if (Q1 ==="Lune") {
score++  numberOfQuestions-- ;
alert("Congrats you got it! " + numberOfQuestions + " to go.");

} else {
alert("Sorry wrong answer " + numberOfQuestions + " to go.");
}
var Q2 = prompt("How many days are in a week?") ;
if (Q2 === 7){
score++  numberOfQuestions-- ;
alert("Congrats you got it! " + numberOfQuestions + " to go.");

} else {
alert("Sorry wrong answer " + numberOfQuestions + " to go.");
}
var Q3 = prompt("Where is liberty statue?") ;
if (Q3 === "new york"){
score++  numberOfQuestions-- ;
alert("Congrats you got it! " + numberOfQuestions + " to go.");

else {alert("Sorry wrong answer " + numberOfQuestions + " to go.");
}
var Q4 = prompt("Who is the current president?") ;
if (Q4 === "Don the moron"){
score++  numberOfQuestions-- ;
alert("Congrats you got it! " + numberOfQuestions + " to go.");

else {alert("Sorry wrong answer " + numberOfQuestions + " to go.");
}
var Q5 = prompt("ARE YOU NOT ENTERTAINED?!") ;
if (Q5 === "IDK AM I?!"){
score++  numberOfQuestions-- ;
alert("Congrats you got it! " + numberOfQuestions + " to go.");

else {
alert("Sorry wrong answer " + numberOfQuestions + " to go.");
}
Adam Beer
Adam Beer
11,314 Points

Code

Wrap your code with 3 backticks (```) on the line before and after. If you specify the language after the first set of backticks, that'll help us with syntax highlighting.

      ```html
      <p>This is code!</p>
      ```

Posting for everyone's reference; Lunette, I'm using Adam Beers method. did some minor formatting, but no code changes.

var numberOfQuestions = 5; 
var score = 0; 
var correct = false; 
/* 
var Q1 = prompt("What's my name?"); 
var Q2 = prompt("How many days are in a week?") ; 
var Q3 = prompt("Where is liberty statue?") ; 
var Q4 = prompt("Who is the current president?") ; 
var Q5 = prompt("ARE YOU NOT ENTERTAINED?!") ; 
var Q1 = prompt("What's my name?");
*/ 
if (Q1 ==="Lune") { 
score++ numberOfQuestions-- ; alert("Congrats you got it! " + numberOfQuestions + " to go.");
} else { 
alert("Sorry wrong answer " + numberOfQuestions + " to go."); 
} 

var Q2 = prompt("How many days are in a week?") ; 

if (Q2 === 7){ 
score++ numberOfQuestions-- ; alert("Congrats you got it! " + numberOfQuestions + " to go.");
} else { 
alert("Sorry wrong answer " + numberOfQuestions + " to go."); 
} 

var Q3 = prompt("Where is liberty statue?"); 

if (Q3 === "new york"){ 
score++ numberOfQuestions-- ; alert("Congrats you got it! " + numberOfQuestions + " to go.");
else {
alert("Sorry wrong answer " + numberOfQuestions + " to go."); 
} 

var Q4 = prompt("Who is the current president?") ; 
if (Q4 === "Don the moron"){ 
score++ numberOfQuestions-- ; alert("Congrats you got it! " + numberOfQuestions + " to go.");
else {
alert("Sorry wrong answer " + numberOfQuestions + " to go."); 
} 

var Q5 = prompt("ARE YOU NOT ENTERTAINED?!") ; 

if (Q5 === "IDK AM I?!"){ 
score++ numberOfQuestions-- ; alert("Congrats you got it! " + numberOfQuestions + " to go.");
else { 
alert("Sorry wrong answer " + numberOfQuestions + " to go."); 
}
Steven Parker
Steven Parker
231,275 Points

I suspect this isn't quite the same as the original, particularly where multiple statements share a line.

Ah, Steven Parker, you are probably right. I guess I was trying to make it more readable, but even doing what little I did may have altered the original code too much.

Steven Parker
Steven Parker
231,275 Points

Only the poster (or a moderator) can fix the formatting accurately. You can delete this one now since Greg fixed the original.

Greg Kaleka
Greg Kaleka
39,021 Points

Hey all, moderator here - I went ahead and added code formatting for everyone's sanity :blush:

5 Answers

Steven Parker
Steven Parker
231,275 Points

It's hard to tell with unformatted code, but it looks like:

  • "Q1" is never defined (it's commented out) but is referenced by the code
  • several of the "if" code blocks are missing a closing brace (})
  • several statements don't end with a semicolon (normally optional, but a problem when they share a line)

Use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area. :arrow_heading_down:   Or watch this video on code formatting. Even better, make a snapshot of your workspace and post the link to it.

Greg Kaleka
Greg Kaleka
39,021 Points

Great pointers, Steven. Lunnette Lucas, I would also suggest you try to add a bit of context to your questions. Code is great, but code-only questions can sometimes be hard to answer. Sharing things like what you've tried, what error messages you're seeing, etc. can be helpful.

Lunnette Lucas
Lunnette Lucas
2,091 Points

Thank you Greg Kaleka, I actually had to take a break from my own stupidity for a minute, glad to to see that the answers I've received are constructive and not from folks that just wanna 'Kick the puppy'.

Steven Parker
Steven Parker
231,275 Points

Hopefully, you can count on answers here being constructive (or at least intended to be). "Kicking the puppy" would clearly be a breach of the Code of Conduct.

Besides, from what I hear, I'm the "bad boy" of the forum. And you've already survived me. :wink:

Lunnette Lucas
Lunnette Lucas
2,091 Points

Ah I see, I believe that previous assumption I had was from my own deeply self critical nature, I shouldn't always expect the worst. Feels good to know that I can ask the appropriate questions without fear. Now when I need to I can spend more time constructing more thought through questions instead of furiously typing and running away from the computer. :D Thanks.

Greg Kaleka
Greg Kaleka
39,021 Points

We try to keep things as beginner-friendly as possible around here. We were all where you were at one point!

Haha yes, no need to run away, and more thought through questions can help you get more thought through answers :+1:

Hi Guys,

My example. Works perfect!

var quest1 = prompt("What is your name?"),
    quest2 = prompt("What is your sorename?"),
    quest3 = prompt("What is your age?"),
    quest4 = prompt("Where do you live?"),
    quest5 = prompt("Do you like icecream?"),
    answer = 0;
 if (quest1.toUpperCase() === 'MARIUS') {
  answer += 1;
 }
 if (quest2.toUpperCase() === 'ZYMANCIUS') {
    answer += 1;
 }  
 if (quest3.toUpperCase() === '34') {
      answer += 1;
 }
 if (quest4.toUpperCase() === 'VILNIUS') {
        answer += 1;
 }
 if (quest5.toUpperCase() === 'YES') {
          answer += 1;
 }
 if (answer == 5) {
  document.write('<h2>You have answered ' + answer + ' questions right. You get gold crown!</h2>') 
 } else if (answer > 2 && answer < 5) {
    document.write('<h2>You have answered ' + answer + ' questions right. You get silver crown!</h2>') 
   } else if (answer >= 1 && answer <= 2) {
      document.write('<h2>You have answered ' + answer + ' questions right. You get bronze crown!</h2>') 
     } else {
        document.write('<h2>You have answered ' + answer + ' questions right. You do not get any crown!</h2>')
       }
Adam Beer
Adam Beer
11,314 Points

Maybe I would change toUpperCase() method to parseInt() like this :

if (parseInt(quest3) === '34')

Yes, Adam,

you are absolutely right :)