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 Solution

When i compare my code using "===" sign then they compare only the first string. why?

this is my code. All is ok but when I tested it then put the similar value of first string later and then put random but ultimately it shows correct, Horrible!

function print(message) { document.write(message); } var que = [ ['what is your name', 'Jolil'], ['The most hit song', 'Daina'], ['Final array of this code', 'Did'] ];

var answer; var sol; var ok; var nice=1; var i = 0; while(i < que.length){ sol = prompt(que[i][0]); answer = que[i][1]; i++; if( sol == answer){ nice++; } }

ok = "You got " + nice + " correct answer(s)"; print(ok);

2 Answers

Brendan Whiting
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,678 Points

Can you explain a little bit more what is going wrong? What are the steps you take when testing, what is your expected result and what is the actual result?

One thing I noticed that might be causing problems: You have code that sets var nice=1;. So nice will always be at least 1 by the end, even if they got no answers correct.

@Brendan Whiting I fixed my problem. Thank you for your response.