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

Elliot Case
Elliot Case
9,032 Points

Can not get the alert box to pop up

Hi can someone please show me the error in my code I can not seem to get the alert message to pop up and not sure what typo I have made. Thanks a lot

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

const fieldTest = isFieldEmpty();

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

1 Answer

Ollie White
Ollie White
6,537 Points

Hi Elliot,

There is a typo on the first line where you are declaring the function isFieldEmpty() where you apear to have miss spelt "function". Change this and then try again. Apart from this i think all your other code should work fine!

I hope this helps, Ollie.

Elliot Case
Elliot Case
9,032 Points

Thanks a lot Ollie! the function works great now.

Ollie White
Ollie White
6,537 Points

No problem, i'm glad to hear it!