Please help with this simple java script code

Associate
Joined
7 Jul 2006
Posts
733
Here's what I need to do:
Delivery is charged @ 1£ per mile above 3 miles

if (distance is less than 3 miles)
Inform of free delivery
else
If (distance is between 3 and 12 miles)
Inform of delivery charge
else
Inform of maximum delivery distance 12 miles



Code:
<SCRIPT LANGUAGE = "JavaScript">

// A delivery charge program 

var distance;
var extraDistance; 

distance = window.prompt('Please enter the distance in miles', '');
distance = parseFloat(distance);




if (distance <= 3)
{
	document.write('You qualify for free delivery');
}
extraDistance = distance - 3
else
 if (distance  > 3 && <= 12);
  {      
    document.write(' You will be charged ' + extraDistance + '£');
}
else 
  {        
    document.write('Our maximum delivery distance is 12 miles!');
}

</SCRIPT>


I don't know where i have gone wrong. Your help is greatly appreciated.
 
Looks like you had a couple of formatting errors.

Code:
<SCRIPT LANGUAGE = "JavaScript">

// A delivery charge program 

var distance;
var extraDistance; 

distance = window.prompt('Please enter the distance in miles', '');
distance = parseFloat(distance);

if (distance <= 3)
{
	document.write('You qualify for free delivery');
}
else
{
	extraDistance = distance - 3;
	if (distance  > 3 && distance <= 12)
	{      
		document.write(' You will be charged ' + extraDistance + '&pound;');
	}
	else 
	{        
		document.write('Our maximum delivery distance is 12 miles!');
	}
}
</SCRIPT>
 
This is for Open University course M150 TMA 02. Next time, do your own homework for assignments and ask your tutor if you get stuck. BUSTED.
 
This is for Open University course M150 TMA 02. Next time, do your own homework for assignments and ask your tutor if you get stuck. BUSTED.

:D

Would love to know who created a new account just to post this!!!!!!
 
It's explicitly against the rules. If he attended his first tutorial, he would also have been treated to a lecture about how the OU tutors search forums like this for posts like his asking for help with coding.

The Assignments section of the Assessment Handbook contains this statement: ‘Posting your own assignments and/or tutor comments on an Open University forum, or on any other website, is not allowed (unless you are required to do so as part of your assignment).’
 
Last edited:
Back
Top Bottom