SitePoint Sponsor

# Thread: I have a question

1. ## 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. 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. Originally Posted by guido2004
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. Originally Posted by guido2004
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.

5. Originally Posted by Logic Ali
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. Originally Posted by Logic Ali
That isn't correct; the program does prompt the user but doesn't perform the required calculation.
You're right. I missed that prompt.
Originally Posted by agater
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. Originally Posted by agater
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?

8. Originally Posted by guido2004

You're missing the part in red.

Now I get it , thanks man (grazie)

#### Posting Permissions

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