Question:

Whats wrong with this java script ?

by  |  earlier

0 LIKES UnLike



its to make you type your name and what color you want your name to be typed in , so can you please help me and tell whats wrong ?

--------------------------------------

<head>

<title>color and name</title>

<!--

<script type = "text/javascript">

var name;

var color;

name = window.prompt( "Please enter your name" );

color = window.prompt( "Enter your choise"

"(1=red,2=blue)", "1" );

if ( color == "1" )

document.writeln( "<h1 style = \"color: red\">" );

document.writeln("welcome to our website" name "enjoy!");

else;

document.writeln( "<h1 style = \"color: blue">");

document.writlen("welcome to our website" name "enjoy");

// -->

</script>

</head>

 Tags:

   Report

5 ANSWERS


  1. There were a lot of errors, but instead of criticizing, I rewrote it.

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

    &lt;!--

    var name;

    var color;

    name = prompt( &quot;Please enter your name&quot; );

    color = window.prompt( &quot;Enter your choise&quot;, &quot;(1=red,2=blue)&quot;, &quot;1&quot; );

    if ( color == &quot;1&quot; )

    {

    document.writeln( &quot;&lt;h1 style = &#039;color: red&#039;&gt;&quot; );

    }

    else

    {

    document.writeln( &quot;&lt;h1 style = &#039;color: blue&#039;&gt;&quot;);

    }

    document.writeln(&quot;welcome to our website, &quot; +name+ &quot;, enjoy&lt;\/h1&gt;&quot;);

    // --&gt;

    &lt;/script&gt;

    For starters, you had a comment start tag before your script tag -- this meant the browser thought the script block was a comment.  For an if-else clause with more than 1 line, you need brackets.  Missing comma after &quot;Enter your choise&quot;, missing +&#039;s in the statement document.writlen(&quot;welcome to our website&quot; name &quot;enjoy&quot;);.

    Your best bet is to run the html in FireFox and use the Error console -- it&#039;s what I did.


  2. a (,) after color = window.prompt( &quot;Enter your choice&quot;

    Hope this helps don&#039;t remember much of javascript(long time no use!)

  3. hey

    color = window.prompt( &quot;Enter your choise&quot;

    at the end there should be a ); and i think you meant to type in choice??

  4. I&#039;m not brillant at reading scripts but have changed some

    name = window.prompt( &quot;Please enter your name&quot; );

    color = window.prompt( &quot;Enter your choise&quot;

    is what needs to be changed so take out Please enter your name but leave the &quot; &quot; in, then in between them add your name same with the colour one.

    also where you see var which is short for variables that&#039;s

    where you can edit the script.

    Make sure you do not take out any codes.

    The best thing to do is to copy and paste the original script on word so you can refer to it and make sure all symbols and codes are exactly the same.

  5. You should close your h1 tags.

    And I think it should &quot;text-color&quot;, not just &quot;color&quot;, but I&#039;m not 100 percent sure on that one.  I don&#039;t bother memorizing CSS, I just play with it until it works :)

    Update:  Contrary to what the person below me said, you are correct to have the comment tag before the script tag.  JS-compliant browsers know to ignore it.  It&#039;s just to make sure non-JS browsers not display your code.  His other advice was great, though.

Question Stats

Latest activity: earlier.
This question has 5 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.
Unanswered Questions