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 trialJerome vanGaalen
18,941 PointsWhat if I wanted to ask more than one question and have it return a value after each question?
I want the program to be able to run, the user answers a question; the program gives the if else answer and then the program asks the second question. The user than anwers that question; the program comes back with a response. Right now with the way I have my code written, the program asks for all the answers to my questions and than tells the user if they are correct.
var answer = prompt("What is the programming language named after a gem?"); if (answer .toUpperCase() === "RUBY"){ document.write ("<p> That is correct! </p>") } else { document.write ("<p> Sorry, That is not correct. :-( </p>") }
var answer2 = prompt ("What is the capital of Colorado?"); if (answer2 .toUpperCse() === "DENVER"){ document.write ("<p> that is Correct! </p>") } else { document.write ("<p> Sorry, that is incorrect </p>") }
3 Answers
Steven Parker
231,271 PointsThis is a guess without seeing the code, but perhaps the program statements just need to be re-ordered. Based on your description, it sounds like the code for asking all the questions comes first and then the code for checking the answers.
Instead, you could alternate the code, and after each question is asked check the answer before going on to ask the next question.
For more specific help, share your code (be sure to format it properly). Even better, make a snapshot of your workspace and post the link to it here.
UPDATE: now that you've added the code, the issue is from using document.write for the feedback. The browser won't render this until the entire program is complete.
For immediate feedback, use the alert function instead.
Michael Maitoza
3,805 PointsHi Jerome, From what I see I think the answer to you question is one of a simple syntax error. This is the code you provided: var answer = prompt("What is the programming language named after a gem?"); if (answer .toUpperCase() === "RUBY"){ document.write ("<p> That is correct! </p>") } else { document.write ("<p> Sorry, That is not correct. :-( </p>") }
var answer2 = prompt ("What is the capital of Colorado?"); if (answer2 .toUpperCse() === "DENVER"){ document.write ("<p> that is Correct! </p>") } else { document.write ("<p> Sorry, that is incorrect </p>") }
Look at the var answer2 line after if and see if there's a spelling error. I hope this helps.
chris kinser
2,800 Pointsvar answer = prompt('What programming language is the name of a gem?'); var rightAnswer = ('Ruby'.toUpperCase()); if ( answer.toUpperCase() === rightAnswer) { document.write("<p>That's right!</p>"); } else { document.write("<p>Sorry, that's wrong.</p>"); }
I wrote mine like this and it worked. You are able to spell ruby any way you want and it will work. Anytime I get an error it is caused by misspelled word or punctuation. There are no auto corrects for this, so always check that first. Good luck. We all need.