PDA

View Full Version : Need Help

beatit
11-10-2010, 10:43 PM
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:(

mrhoo
11-10-2010, 10:54 PM

beatit
11-10-2010, 11:21 PM

<html>

<script type="text/javascript">
var distance=1;

distance = window.prompt("How many miles is the distance", "");

if (distance <= 3)
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>

</html>

Old Pedant
11-10-2010, 11:39 PM
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?

Philip M
11-11-2010, 08:28 AM
It is hard to calculate the delivery charge as the charge per mile is not specified. :eek:

Check the syntax of if...else statements. It is else if { and not else { if

Old Pedant
11-12-2010, 12:04 AM