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 trialOliver Sewell
16,425 PointsHow do i add the .toUpperCase() its not working ?
var correct = 0;
var questions = 3;
var questionsLeft = '[ ' + questions + ' questions Left ]';
questions -= 1;
var correctGuess = false;
var answerOne = "Yellow";
var questionOne = prompt("What color is the sun?" + questionsLeft);
if ((questionOne.toUpperCase())=== answerOne) {
document.write('<p> the answer' + answerOne + 'is correct </p>');
correct += 1;
} else {
document.write("<p> Sorry! you are incorrect</p>");
}
questionsLeft = '[' + questions + ' questions Left ]';
questions -= 1;
var answerTwo = "Blue";
var questionTwo = prompt('What colour is the sky' + questionsLeft);
if ((questionTwo.toUpperCase()) === answerTwo) {
document.write('<p> Well done! the answer' + answerTwo + 'is correct </p>');
correct +=1;
} else {
document.write ("<p> Sorry you are incorrect </p>");
}
questionsLeft = '[' + questions + ' questions Left ]';
questions -= 1;
var answerThree = "Green";
var questionThree = prompt('What colour is the grass' + questionsLeft);
if ((questionThree.toUpperCase()) === answerThree) {
document.write('<p> Well done! the answer' + answerThree + 'is correct </p>');
correct +=1;
} else {
document.write ("<p> Sorry you are incorrect </p>");
}
document.write ("<p> You got" + correct +" out of 3 questions.</p>");
if ( correct === 3 ) {
document.write('<p> Well Done! you earned a Gold crown </p>');
}
if ( correct === 2 ) {
document.write('<p> Well Done! you earned a Silver crown </p>');
}
if (correct === 1) {
document.write('<p> Well Done! you earned a Bronze crown </p>');
}
.toUpperCase() makes the answers wrong but unsure where to put it
1 Answer
Sara Hardy
8,650 PointsYou are calling .toUpperCase() on their answer, but comparing it to your correct answer that is not all uppercased. YELLOW is not equal to Yellow. You need to call .toUpperCase() on both for a proper comparison.
if ((questionOne.toUpperCase())=== answerOne.toUpperCase()) {