If and Else Statementments Bug

I have been studying basic JavaScript lately and have run into a problem. My code is as follows:

<html>
     <body>
          <script type="text/javascript">
                 var name= window.prompt("Type Your Name.")
                 if ( (name=='Ethan') )
                    document.write("You LOVE BACON!!!")
                 else
                     document.write("You Have not entered your name in yet.")
          </script>
     </body>
</html>

My problem is that when I run the code and enter my name, the page will say the following:

Do you like BACON !!! You have not entered your name yet.

The My else statement also appears with my if statement.

+5
source share
2 answers

try it

if ( name=='Ethan' ) //see here
                    document.write("You LOVE BACON!!!");      // Function Call!
                 else
                     document.write("You Have not entered your name in yet."); // 
0
source
<html>
     <body>
          <script type="text/javascript">
                 var name = window.prompt("Type Your Name."); // Assignment!
                 if ( name=='Ethan' )
                    document.write("You LOVE BACON!!!");      // Function Call!
                 else
                     document.write("You Have not entered your name in yet."); // Function Call!
          </script>
     </body>
</html>

Half-columns go at the end of each statement after each function call or assignment in this case.

+1
source

All Articles