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 :

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

Homework? :smiley:

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:D

you mean this point :

• Read the distance in miles from the user.

how can I fix it ??

That isn’t correct; the program does prompt the user but doesn’t perform the required calculation.

so my code is correct ? are not?

You’re right. I missed that prompt.

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.

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?

Now I get it , thanks man (grazie)