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
brandonlind2
7,823 PointsI can't figure out this programming problem
Every time a question is answered it always comes back as wrong and the program stops running immediately after the question4 prompt, any ideas as to why?
var questionsLeft= 5;
var questionsCorrect;
var question1= prompt("What language is named after a gem?");
questionsLeft-=1;
if(question1=== "ruby".toUpperCase()) {questionsCorrect+=1; alert("correct! [You have " + questionsLeft + " left]");}
else {alert("sorry, the correct answer was ruby. [You have " + questionsLeft + " left]");}
When a question is answered in the prompt it always comes back as wrong and the program stops running immediately after the question4 prompt. Any ideas as to why this is?
var question2= prompt("What language is named after a snake?");
questionsLeft-=1;
if(question2==="python".toUpperCase()) { questionsCorrect+=1; alert("correct!, [you have " + questionsLeft + " left]");}
else{alert("sorry, the answer was python [You have " + questionsLeft + " left]");}
var question3= prompt("What language is this program written in?");
questionsLeft-=1;
if(question3=== "javascript".toUpperCase()) {alert("correct! [You have " + questionsLeft + " left");
questionsCorrect+=1; alert("correct! [you have " + questionsLeft + " left]");}
else{alert("sorry, the answer was javascript [You have " + questionsLeft + " left]");}
var question4= prompt("What language styles a webpage?");
questionsLeft-=1;
if(question4=== "css".toUpperCase()){ questionsCorrect+=1; alert("correct!, [you have " + questionsLeft + " left]");}
else{alert("sorry, the correct answer was css [you have " + questoinsLeft + " left]");}
var question5= prompt("What language structures a webpage?");
questionsLeft-=1;
if(question5=== "html".toUpperCase()){questionsCorrect+=1; alert("correct! [You have " + questionsLeft + " left]");}
else{alert("sorry, the correct answer html [You have " + questionsLeft + " left]");}
if(questionsCorrect=== 5){alert("you recieved a gold crown");}
if(questionsCorrect > 4) {alert("You recieved a silver crown");}
if(questionsCorrct > 2) {alert("You recieved a bronze crown");}
else{alert("sorry, You recieved no crown");}
2 Answers
miikis
44,957 PointsHey Brandon,
You have a typo on the second alert call for question4: it says 'questoinsLeft' and it should say 'questionsLeft'. That should solve your error.
A Laypanov
27,579 PointstoUpperCase() is used here to eliminate possible issue on letter case with user input, so "Ruby", "ruby" and "RUBY" will result correct answers. In your example you are applying this method to predefined, test string, which is not wrong, but defeats the purpose. Instead you should use this method on the user string: question1.toUpperCase() === "RUBY"