Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Dec 2006
    Location
    Malaysia.
    Posts
    32
    Thanks
    19
    Thanked 0 Times in 0 Posts

    why my coding is not working? can u help me?

    THis is the question

    Write a compound conditional statement that tests whether a previously declared variable named finalScore is greater than or equal to 90, less than 90 but greater than or equal to 80, less than 80 but greater than or equal to 70, or less than 70. Do not use any logical operators (“and” or “or”). Depending on which condition is satisfied, the code should display an alert box message with an appropriate message (e.g., “Final score is in the 80s” or “Final score is below 70”).

    _______________________________________________________________

    Here are the coding... did i missed out something... please help me!


    <html>
    <head>
    <title>Question 4</title>

    <script type="text/javascript">
    <!--
    var finalScore,

    finalScore=window.prompt( "Enter a final score:",'');

    if (finalScore<70)
    {
    document.writeln(finalscore.Final score is below 70);
    }
    else if(finalScore<80)
    {
    document.writeln(finalscore.Final score is in the 70s);
    }
    if (finalScore<90)
    {
    document.writeln(finalscore.Final score is in the 80s);
    }
    else{
    document.writeln(finalscore.Final score is over 90);
    }
    alert(finalscore)
    //-->
    </script>
    </head>
    <body>
    <p>Click Refresh (or Reload) to run the script again<p>
    </body>
    </html>

  • #2
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    What problem are you having?

    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #3
    New Coder
    Join Date
    Dec 2006
    Location
    Malaysia.
    Posts
    32
    Thanks
    19
    Thanked 0 Times in 0 Posts
    once if i run the source document... the window prompt message should appear and that will allow the users to typed number. but the prompt message has not appear at all...

  • #4
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    This code seems to work:
    Code:
    <html>
    <head>
    <title>Question 4</title>
    
    <script type="text/javascript">
    <!--
    var finalScore=window.prompt("Enter a final score:")
    var text
    
    if(finalScore < 70)
    {
    	text="Score was less than 70.";
    	//document.writeln(text);	
    }
    if(finalScore > 69 && finalScore < 80)
    {
    	text="Score was in the 70s";
    	//document.writeln(text);	
    }
    if(finalScore > 79 && finalScore < 90)
    {
    	text="Score was in the 80s";
    	//document.writeln(text);	
    }
    if(finalScore > 89 && finalScore < 100)
    {
    	text="Score was in the 90s";
    	//document.writeln(text);	
    }
    if(finalScore > 99)
    {
    	text="Perfect Score!";
    	//document.writeln(text);	
    }
    
    window.alert(text)
    //-->
    </script>
    </head>
    <body>
    <p>Click Refresh (or Reload) to run the script again<p>
    </body>
    </html>
    It seems to do with the fact that you used elseif statements... don't ask me why..

    Also, your statements may not have been specific enough, I.E. a score in the 60s would qualify for ALL the IF statements...

    Also, window.alert() seemed to work better than alert()...

    HTH
    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •