I have this question :
- 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 .