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) Creating Reusable Code with Functions Getting Information From a Function

Why does my code work ?

When I execute my code , the prompt comes up even though it is located in the function and I did not call the function anywhere , so even when I did not call the function why is the prompt still coming up ?

function emailStatus () 
{
var x = prompt("Type in your email");
  if ( x === '')
  {
  return false ;  
  }
  else { 
  return true ; 
  }
}
if (emailStatus() === true )
{
alert("Cool");
}
else 
{
alert("Please do not leave the email as blank");
}

1 Answer

Rune Andreas Nielsen
Rune Andreas Nielsen
5,354 Points

Hi Bavan,

You're calling the emailStatus function inside of your if clause if (emailStatus() === true )