Help - Search - Members - Calendar
Full Version: Javascript:just Started Learning
BleepingComputer.com > Software > Programming
   
mihangel
Can anyone give me a few pointers on this Java code I'm supposed to write. I know it's a mess but i've only been learning for a few weeks from a book, and not finding it very easy.
........................................

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

<HTML>
<HEAD>
<TITLE> Delivery Charges
</TITLE>
<script LANGUAGE = “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?','');



If (order <= £25)
{
document.write (‘ Your order value is £ ' + £3)
}
else
{
If (order >= £25) && (order <£100)
{
document.write (‘your order value is £’ ’)
}
else
{
If (order >£100)
{
Document.write (‘congratulations, your order has earned you a free gift’)
}
document.write('<BR>');
document.write('Thank you for shopping with us.');

</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>
........................................

Many thanks in advance for your help.

Mihangel

(Moderator edit: Revised Topic Title and added Topic Description. jgweed)
mihangel
I've actually managed to get half way through this myself, after reading through the chapter a million times crazy.gif i started to get a feel for it.I am stuck on one part i could do with help on,when i want to
show that an order is more than £25 but less than £100. I've tried
if (orderValue >= £25) && (orderValue<£100) but that doesn't work.

Any pointers would be greatly appreciated.
Thanx in advance Mihangel
groovicus
Remove the pound sign.
if (orderValue >= 25) && (orderValue<100)

Also, that is Javascript, not Java. They are completely different. smile.gif
mihangel
Thanks for the reply groovy, I'm getting there slowly.I'm a bit behind because my internet connection has been on the blink for the last four weeks(orange say there is a line fault and BT say they have done a line check and it's OK blink.gif blink.gif ) The online activities for this book are inaccessible to me so I'm a bit behind.
This is where i am with the script, but something/s are stopping it running.

<HTML>
<HEAD>
<TITLE>
Deliverycharge
</TITLE>
<script LANGUAGE = "JavaScript">

var orderValue; // How much the order is worth

orderValue = window.prompt ('How much is your order in pounds sterling?','');
if (orderValue <= 25);
{
document.write ('Your order is valued at £'+ orderValue + ' plus £3 delivery charge' + '<BR>');
document.write ('Thank you for your custom' + '<BR>');
}

else
{
if ((orderValue >= 25) && (orderValue < 100));
{
document.write ('Your order is valued at £'+ orderValue' + '<BR>');
document.write ('Thank you for your custom' + '<BR>');
}

else
{
if (orderValue >= 100);
{
document.write ('Your order is valued at £'+ orderValue' + '<BR>');
document.write ('Your order has earned you a free gift, thank you shopping with us' + '<BR>');
}
}
}

</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>




The first document.writes seem to be repeating themselves.
As always any pointers are greatly appreciated.
Thanks again Mihangel.
groovicus
If you are using 25 to test your values, it is going to repeat because you are checking for = 25 in both cases. What other test data are you using?

Also, instead of saying "Thank you for your custom", I think what you probably want to say is "Thank you for your order".

This line:
document.write ('Thank you for your custom' + '<BR>');
Should be moved to be the last line printed so that it only appears once in your source code.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.