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

Jeremy Coleman
Jeremy Coleman
5,449 Points

Issue with IF statement and Booleans..

So, I am having issues getting this code to work properly. I think I know the problem. The response of true and false is a string and not a boolean. So, how would I go about turning a string into a boolean?

var quest1 = prompt("True or False. There are 196 official countries in the world today?"); //Answer is false.

if (quest1 === false ) { alert("Correct!"); } else { alert("Wrong!"); };

2 Answers

Nhat Nguyen
Nhat Nguyen
4,669 Points

You can fix that by changing false to "false". Javascript will then interpret that as a comparision between your string and the string "false".

Jeremy Coleman
Jeremy Coleman
5,449 Points

Ah thank you! That fixed my problem.. Been struggling with that for a hour or 2 lol