/    Sign up×
Community /Pin to ProfileBookmark

Delivery charge program

It’s just a work in progress at the moment, but I’d appreciate some help, again.

I’m writing a program for a delivery service where there are following conditions.

For orders worth less than £25 the delivery charge is £3.00.

Orders worth at least £25 but less than £100 are delivered free.
Orders worth £100 or more are delivered free and in addition the
customer receives a free gift. I prompt the user to enter the order value, and tell him/her which band he comes under.

This is what I have so far, and it doesn’t seem to be it, evidently.

[code]
<html>
<body>
<script type=’text/javascript’>
// A delivery charge program

var ordervalue // how much the order is worth
ordervalue = window.prompt (‘How much is the order worth in Pounds Sterling?’,”);
document.write (‘The value of your order is £’ + ordervalue + ‘.<BR>’);
if ordervalue =< 25
{
document.write(‘Your delivery will cost £3 as your order value is’ + ‘£’ + ordervalue + ‘.<BR>’);
if ordervalue > 25 and ordervalue < 100
document.write(‘Your delivery is free as your order value is’ + ‘£’ + ordervalue + ‘.<BR>’);
else
document.write (‘You will receive a free gift and delivery is free as your order value is’ + ‘£’ + ordervalue + ‘.<BR>’);
}
</script>
</body>
</html>
[/code]

to post a comment
JavaScript

13 Comments(s)

Copy linkTweet thisAlerts:
@rootMay 13.2007 — After a bit of tweaking and changes...
<i>
</i>[COLOR="Silver"]&lt;html&gt;
&lt;body&gt;
&lt;script type='text/javascript'&gt;
// A delivery charge program

var ordervalue[/COLOR][b][SIZE="2"][COLOR="DarkRed"];[/COLOR][/SIZE][/b][COLOR="silver"] // how much the order is worth
ordervalue = window.prompt ('How much is the order worth in Pounds Sterling?','');[/COLOR]
[b][COLOR="darkred"]str=[/COLOR][/b][COLOR="silver"]'The value of your order is £' + ordervalue;
if [/COLOR][b][COLOR="darkred"]([/COLOR][/b][COLOR="silver"]ordervalue [/COLOR][b][COLOR="darkred"]&lt;=[/COLOR][/b] [COLOR="Silver"]25[/COLOR][b][COLOR="darkred"]) str=[/COLOR][/b][COLOR="silver"]'Your delivery will cost £3 as your order value is £' + ordervalue';
if [/COLOR][b][COLOR="darkred"]([/COLOR][/b][COLOR="silver"]ordervalue &gt; 25 [/COLOR][b][COLOR="darkred"]&amp;&amp;[/COLOR][/b] [COLOR="silver"] ordervalue &lt; 100[/COLOR][b][COLOR="darkred"]){[/COLOR][/b]
[b][COLOR="darkred"]str=[/COLOR][/b][COLOR="silver"]'Your delivery is free as your order value is £' + ordervalue';[/COLOR]
[b][COLOR="darkred"]}[/COLOR][/b]else [b][COLOR="darkred"]str=[/COLOR][/b][COLOR="silver"]'You will receive a free gift and delivery is free as your order value is £' + ordervalue;[/COLOR]
[b][COLOR="darkred"]alert(str);[/COLOR][/b] [COLOR="silver"]// to output a result to see it is works!
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;[/COLOR]

This is untested and likely to be buggy but you really should pay a site like :http://www.htmlgoodies.com/ a visit, it will help you understand how 2 write scripts.
Copy linkTweet thisAlerts:
@viper12authorMay 13.2007 — It doesn't work, sadly. Thanks for trying though.
Copy linkTweet thisAlerts:
@viper12authorMay 13.2007 — Anyopne else know what to do? I'm eager to find out, and can't sleep now.
Copy linkTweet thisAlerts:
@viper12authorMay 13.2007 — <i>
</i>&lt;html&gt;
&lt;body&gt;

&lt;head&gt; DELIVERY CHARGE PROGRAM &lt;/head&gt;

&lt;br&gt;

&lt;script type="text/javascript"&gt;
/* Program to provide descriptive information about the orderValue, given its value */

var orderValue

orderValue = window.prompt('How much is the order worth in Pounds Sterling?','');
orderValue = parseFloat(orderValue);
var orderString;

if(orderValue &lt; 25)
{
orderString = "£3.00";
orderValue += 3;
}
else if(orderValue &lt; 100.00)
{
orderString= "free";
}
else
{
orderString = "free with free gift";
} <br/>
orderValue = orderValue.toFixed(2);
document.write('Delivery charge is ' + orderString + '. The value of your order is £' + orderValue + '.&lt;br /&gt;');
document.write('&lt;br /&gt;');
&lt;/script&gt;
&lt;body&gt;
&lt;html&gt;


Now this works just fine in an HTML editing program called Taco HTML I use on my Mac, but it doesn't seem to execute in firefox, can someone help please?
Copy linkTweet thisAlerts:
@boskoMay 13.2007 — Based on . changes:
[CODE]<html>
<body>
<script type='text/javascript'>
// A delivery charge program var ordervalue
// how much the order is worth
var ordervalue = window.prompt('How much is the order worth in Pounds Sterling?','');

var str = 'The value of your order is £' + ordervalue + '<br>';
if (ordervalue <= 25)
str ='Your delivery will cost £3 as your order value is £' + ordervalue;
if (ordervalue > 25 && ordervalue < 100){

str ='Your delivery is free as your order value is £' + ordervalue;

}
else
str ='You will receive a free gift and delivery is free as your order value is £' + ordervalue;
alert(str);
// to output a result to see it is works!
</script>
</body>
</html>[/CODE]
Copy linkTweet thisAlerts:
@viper12authorMay 13.2007 — That one doesn't work proper, bosko, the code I've just pasted does, but for some reason, not in an internet browser.
Copy linkTweet thisAlerts:
@rootMay 13.2007 — I just tested it and it works perfectly fine thank you. except for the buggy bit I mentioned, something in the logic int right!
Copy linkTweet thisAlerts:
@rootMay 13.2007 — here:
&lt;html&gt;
&lt;body&gt;
&lt;script type='text/javascript'&gt;
// A delivery charge program var ordervalue
// how much the order is worth
var ordervalue = window.prompt('How much is the order worth in Pounds Sterling?','') -0; <br/>
var str = 'The value of your order is £' + ordervalue + '&lt;br&gt;';
if (ordervalue &lt;= 25)
str ='Your delivery will cost £3 as your order value is £' + ordervalue;
if (ordervalue &gt; 25 &amp;&amp; ordervalue &lt; 100){ <br/>
str ='Your delivery is free as your order value is £' + ordervalue; <br/>
}
else if(ordervalue &gt;=100){
str ='You will receive a free gift and delivery is free as your order value is £' + ordervalue;}
alert(str);
// to output a result to see it is works!
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;

WORKS.
Copy linkTweet thisAlerts:
@rootMay 13.2007 — NOTE the -0; on the end of the prompt, this turns a string numeric into a number numeric so you can add, subtract, divid, etc
Copy linkTweet thisAlerts:
@viper12authorMay 13.2007 — It seems to work to the point that it accepts the value, but doesn't print whether the order delivery costs 3 quid, free or free with a gift, ..

That's the key part, aye.

I take that back, it works, it works.

Thanks a lot slash slash. ?
Copy linkTweet thisAlerts:
@rootMay 13.2007 — The NEW one works.... I put 15 into the box and the £3 thing poped up. I put 50 in and it says free delivery, and put a ton in and its offering me a freebie.

Edit:

K, I was beginning to wonder!
Copy linkTweet thisAlerts:
@rootMay 13.2007 — One thing tho...

str += '... for the remaining 3 str = but not the first, this is because your adding to the string and not setting, my typo error...!
Copy linkTweet thisAlerts:
@viper12authorMay 13.2007 — Thanks a lot, mate, most thankful I am. Yoda, style.
×

Success!

Help @viper12 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...