SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Member
    Join Date
    Nov 2010
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I have a question

    I have this question :

    1. A new restaurant offers free delivery within a three-mile radius, that is, up to and including three miles from their location. [15]
    For distances over three miles and not exceeding 12 miles, there is a charge of £1 per extra mile over the first three.
    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.

    and I wrote a java script code like this :

    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> 
    is my answer wrong or right .

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,508
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Homework?

    Anyway, your program doesn't ask the user to input the distance, it has a distance of 1 hardcoded, so you didn't cover the first dot.

  3. #3
    SitePoint Member
    Join Date
    Nov 2010
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post
    Homework?

    Anyway, your program doesn't ask the user to input the distance, it has a distance of 1 hardcoded, so you didn't cover the first dot.
    thank you man

    you mean this point :

    • Read the distance in miles from the user.

    how can I fix it ??

  4. #4
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post
    Homework?

    Anyway, your program doesn't ask the user to input the distance, it has a distance of 1 hardcoded, so you didn't cover the first dot.
    That isn't correct; the program does prompt the user but doesn't perform the required calculation.
    Tab-indentation is a crime against humanity.

  5. #5
    SitePoint Member
    Join Date
    Nov 2010
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Logic Ali View Post
    That isn't correct; the program does prompt the user but doesn't perform the required calculation.

    so my code is correct ? are not?

  6. #6
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,508
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by Logic Ali View Post
    That isn't correct; the program does prompt the user but doesn't perform the required calculation.
    You're right. I missed that prompt.
    Quote Originally Posted by agater View Post
    so my code is correct ? are not?
    Your code doesn't do all things asked:
    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.
    You're missing the part in red.

  7. #7
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by agater View Post
    so my code is correct ? are not?
    From what you say I don't think you've even tried to execute your code.
    When run does it appear to do what is asked?
    Tab-indentation is a crime against humanity.

  8. #8
    SitePoint Member
    Join Date
    Nov 2010
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post

    You're missing the part in red.

    Now I get it , thanks man (grazie)


Bookmarks

Posting Permissions

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