Hi All,

I was testing this code someone gave me on the forum earlier, and I am having a hard time understanding why I get this weird result:

Code:
<SCRIPT language="JavaScript"> 
<!--hide  
 var yourname= prompt('Please enter your name, so you can get a special greeting', ' ');

 if ( (yourname==' ') || (yourname==null) ) 
 { 
   yourname="Dude"; 
 } 

//--> 
</SCRIPT> 

</HEAD> 

<BODY> 

<SCRIPT language="JavaScript"> 
<!--hide 
 document.write("<CENTER><H1>Hello, " + yourname + " ! Welcome to My Page! <\/H1><\/CENTER>");

//--> 
</SCRIPT> 

</BODY>
If the user presses ok with nothing entered, or presses cancel your name is changed to dude.

Now I did a little modification on the code
Code:
<SCRIPT language="JavaScript"> 
<!--hide  
 var yourname= prompt('Please enter your name, so you can get a special greeting', ' ');

 if ( yourname==' ')  
 { 
   yourname="Dude"; 
 } 

//--> 
</SCRIPT> 

</HEAD> 

<BODY> 

<SCRIPT language="JavaScript"> 
<!--hide 
 document.write("<CENTER><H1>Hello, " + yourname + " ! Welcome to My Page! <\/H1><\/CENTER>");

//--> 
</SCRIPT> 

</BODY>
I just took out the (yourname==null), so that the only parameter in the if statement is yourname==' '. WHich means the name is changed to "dude" only if the user presses cancel, and not when they press ok with nothing entered. Yet when I try this code, I continue to get null for the name now.

What is going on?