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 Basics (Retired) Making Decisions with Conditional Statements The Conditional Challenge Solution

Yuichi Narisawa
Yuichi Narisawa
19,548 Points

My code of the quiz challenge.

I wrote the code like this.

//Start the counter

var correctA = 0;

//questions & answers var a1 = prompt('Where is the capital of Japan?'); if (a1.toLowerCase === 'tokyo'){ correctA += 1; } var a2 = prompt('3*2+(42+2) = ?'); if (parseInt(a2) === 50){ correctA += 1; } var a3 = prompt('Where is the capital of America?'); if (a3.toLowerCase() === 'washington'){ correctA += 1; } var a4 = prompt('Where is the capital of Canada?'); if (a4.toLowerCase() === 'ottawa'){ correctA += 1; } var a5 = prompt('Where is the capital of France?'); if (a5.toLowerCase() === 'paris'){ correctA += 1; }

//Check the Correct number of Answers

document.write('<p><strong>You got '+ correctA +' questions!</strong></p>');

//add crown if (correctA >= 5 ){ document.write('<p>Gold Crown! Congratulations!</p>'); } else if (correctA >=3 ){ document.write('<p>Silver Crown! Great job!</p>'); } else if (correctA >=1 ){ document.write('<p>Blonze Crown! Good job.</p>'); } else { document.write('<p>Maybe Nexttime!</p>'); }

//Out put Answers document.write(a1); document.write(a2); document.write(a3); document.write(a4); document.write(a5);

But, I cannot get 5 correct answers. It seems that the "a2" answer is a problem. Could someone give me advice?

1 Answer

Hello, i think you are missing closing brackets () if (a1.toLowerCase === 'tokyo') This should be if (a1.toLowerCase() === 'tokyo')

Yuichi Narisawa
Yuichi Narisawa
19,548 Points

Thanks for taking your time to answer my question! I thought it would be okey if I omit the () after toLowerCase, but isn't. Thank you for your advice and I, finally, could get the Gold crown!