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 Functions Create Reusable Code with Functions Using Multiple return Statements

Kendall McCall
Kendall McCall
8,177 Points

My alert is not working can someone spot my error?

function isFieldEmpty() { const field = document.querySelector('#info'); if (!field.value) { return true; } else { return false; } }

const fieldTest = isFieldEmpty();

if (fieldTest) { alert('Please provide your information.'); }

Hi Kendall McCall ,

What type of element #info is ?

Thanks,

2 Answers

Make sure you remove the comment surrounding the '#info' div on the index file. Otherwise there is nothing for the querySelector to grab. Opening up the console should give you more information as to what's going on.

Hi Kendall McCall

Did you remove the value attribute from the input element?

If you didn't, then your condition will be false and you won't see the alert.