Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

1. ## 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

• Originally Posted by mrhoo
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>  ```

• 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?

• 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

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?

•

#### Posting Permissions

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