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 6 of 6

Thread: Need Help

  1. #1
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Need Help

    Hello,
    I have this question :



    a. Write a complete JavaScript program which will work according to the following specifications:

    Read the distance in miles from the user.

    If the distance is within three miles (i.e. less than or equals to 3), the user should be informed that the delivery will be free;

    If the distance is over three miles but not over 12 miles, the user should be informed what the delivery charge is in pounds. To do this, you need first to calculate the extra distance. You should store the value in the variable which is already declared, then use this variable when you output the message.

    If the distance exceeds 12 miles, the user should be informed that the company’s maximum delivery distance is 12 miles.



    I tried to solve it many times , but the code did'nt work

    Last edited by beatit; 11-10-2010 at 10:45 PM.

  • #2
    Regular Coder
    Join Date
    Mar 2006
    Posts
    728
    Thanks
    35
    Thanked 132 Times in 123 Posts
    Show your best try.

  • #3
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by mrhoo View Post
    Show your best try.
    PHP Code:
    <html>
    <
    head>

    <
    script type="text/javascript">
    var 
    distance=1;

    distance window.prompt("How many miles is the distance""");

    if (
    distance <= 3)   
    window.alert("the delivery will be free")
    else    
    {    if ((
    distance 3)&& (distance 12)) 
    window.alert("the delivery charge is in pounds")
    else    
    {    if (
    distance >12
    window.alert("the company maximum delivery distance is 12 miles")
                   
    }
    }
    </script>

    </head>
    </html> 

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,603
    Thanks
    80
    Thanked 4,634 Times in 4,596 Posts
    To do this, you need first to calculate the extra distance. You should store the value in the variable which is already declared, then use this variable when you output the message.
    Where is your code that does any of that?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,304
    Thanks
    203
    Thanked 2,562 Times in 2,540 Posts
    It is hard to calculate the delivery charge as the charge per mile is not specified.

    Check the syntax of if...else statements. It is else if { and not else { if

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,603
    Thanks
    80
    Thanked 4,634 Times in 4,596 Posts
    Well, I read this:
    the user should be informed what the delivery charge is in pounds. To do this, you need first to calculate the extra distance. You should store the value in the variable which is already declared, then use this variable when you output the message.
    to mean that the charge is 1 pound per mile in excess of 3.

    But who knows?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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