JavaScript JavaScript Basics Creating Reusable Code with Functions Getting Information From a Function

bavan .
bavan .
2,638 Points

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,252 Points

Hi Bavan,

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