Question:

JavaScript code??!! help me!!

by  |  earlier

0 LIKES UnLike

whats wrong!!!??

<head>

<script language="JavaScript">

<!--hide

var username

var user1="Spiderpig1"

username=prompt("Please write your

username below:")

if (user1==username)

{

alert("Welcome back to Spellingbees,

Simpsonspig1.")

}

else

{

alert("AHHHHHHHHH!!!!! Well, fine, I will

"obligate" you access to this site. Gosh!!!")

}

//-->

</script>

</head>

 Tags:

   Report

2 ANSWERS


  1. Mehdi, since the prompt() method evaluates a string, to recast the method as a new String object as you did is not recommended and is not a best practice. It is also not necessary to declare the user1 variable explicitly as a string either. The rest of your reply to the original poster was spot-on.


  2. Several things:

    1. You&#039;re using obsolete code. Ditch the &lt;!-- and //--&gt; Also, don&#039;t use the &quot;language&quot; attribute, use &quot;type&quot;.

    2. End each command line with a semicolon

    3. Use correct, up to date JavaScript.

    4. Don&#039;t use double quotes in a string that&#039;s inside double quotes.

    &lt;script type=&quot;text/JavaScript&quot; &gt;

    var user1 = new String ( &#039;Spiderpig1&#039; );

    var username = new String ( prompt ( &#039;Please write your

    username below:&#039; ) );

    if ( user1 == username ) {

    alert ( &#039;Welcome back to Spellingbees,

    Simpsonspig1&#039; );

    }else{

    alert ( &#039;AHHHHHHHHH!!!!! Well, fine, I will

    &quot;obligate&quot; you access to this site. Gosh!!!&#039; );

    }

    &lt;/script&gt;

    EDIT:

    You make a very valid point, mnmboy.

    I&#039;ve gotten into the habit of always declaring strings *as* strings, because that will allow my editor to use auto-code... which in turn guarantees me that if I call a string function (like .Search, or .ToLowerCase, for example), it&#039;ll work.

    For what the strings are used for in this question, the declarations may, indeed, be superfluous.

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.