Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Javascript:just Started Learning


  • Please log in to reply
4 replies to this topic

#1 mihangel

mihangel

  • Members
  • 25 posts
  • OFFLINE
  •  
  • Location:South Wales
  • Local time:12:18 PM

Posted 08 May 2007 - 10:15 AM

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)

Edited by jgweed, 11 May 2007 - 07:25 AM.


BC AdBot (Login to Remove)

 


#2 mihangel

mihangel
  • Topic Starter

  • Members
  • 25 posts
  • OFFLINE
  •  
  • Location:South Wales
  • Local time:12:18 PM

Posted 11 May 2007 - 04:00 AM

I've actually managed to get half way through this myself, after reading through the chapter a million times :thumbsup: 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

#3 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:03:18 AM

Posted 11 May 2007 - 12:24 PM

Remove the pound sign.
if (orderValue >= 25) && (orderValue<100)

Also, that is Javascript, not Java. They are completely different. :thumbsup:

#4 mihangel

mihangel
  • Topic Starter

  • Members
  • 25 posts
  • OFFLINE
  •  
  • Location:South Wales
  • Local time:12:18 PM

Posted 12 May 2007 - 06:24 AM

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 :thumbsup: :flowers: ) 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.

Edited by mihangel, 13 May 2007 - 03:58 AM.


#5 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:03:18 AM

Posted 13 May 2007 - 09:33 AM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users