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

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
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,735 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.