Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Loops, Arrays and Objects Tracking Multiple Items with Arrays Build a Quiz Challenge, Part 1

Cannot get my code to add lowercase answers as correct. HALP

So I'm obviously new to JavaScript and I've been looking at my code for a while attempting to come up with solutions for having my answers (madrid, dublin, london) all accepted in lowercase.

It currently works fine when entering the answers in uppercase.

I can imagine that there are various ways to make this code more efficient so any feedback would be appreciated however I'm really just looking to understand why neither the following two approaches seem to work

a) answer = answer..toUpperCase (added below "answer = prompt(quiz [i][0])")

b) creating a function to convert the prompt's input to uppercase and then calling the function before the if statement.


```var quiz = [ ['What is the capital of Spain?', 'MADRID'], ['What is the capital of Ireland?', 'DUBLIN'], ['What is the capital of England?', 'LONDON'] ]; var answer; var score = 3; var correct = []; var inCorrect = [];

for (var i = 0; i < quiz.length; i += 1) { answer = prompt(quiz [i][0]) if (answer != quiz[i][1]) { inCorrect.push(quiz[i][0]) --score; } else { correct.push(quiz[i][0]) } }

function displayHTML() { document.write(message); }

var message = ("You got " + score + " question(s) right." + "<p><h2> You got these questions correct: </p></h2>" + "<p>" + correct.join('<p> ') + "</p>" + "<p><h2> You got these questions incorrect: </p></h2>" + inCorrect.join('<p> '));


1 Answer

Steven Parker
Steven Parker
220,450 Points

You can call the conversion function within the "if":

     if (answer.toupperCase() != quiz[i][1]) {

And when posting code to the forum, use Markdown formatting to preserve the appearance (as I have done here).