I have managed to get the prompt to work, but when i type a number into prompt it displays all outputs on webpage, like nodiscount5%discount etc, could someone please sort my program so it just shows one output, then i can study my errors and learn from it. thankyou.
<HTML>
<HEAD>
<TITLE>Volume Discount</TITLE>
<SCRIPT LANGUAGE = "JavaScript">
// A program to tell a customer what volume discount they can expect.
var numberOfGiftBoxes;
numberOfGiftBoxes = window.prompt
('Please enter now many boxes you are purchasing.', '');
numberOfGiftBoxes = parseFloat(numberOfGiftBoxes);
if (numberOfGiftBoxes <= 3)
{
document.write("no discount");
}
if (numberOfGiftBoxes >= 4) ! (numberOfGiftBoxes <= 11)
{
document.write("5% discount");
}
if (numberOfGiftBoxes >= 12) ! (numberOfGiftBoxes <= 29)
{
document.write("10% discount");
}
if (numberOfGiftBoxes >=30)
{
document.write("20% discount");
}
</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>
I didn't post the complete page code, just the part that I thought needed to be changed.
The complete code should be like this:
<HTML>
<HEAD>
<TITLE>Volume Discount</TITLE>
<SCRIPT LANGUAGE = "JavaScript">
// A program to tell a customer what volume discount they can expect.
var numberOfGiftBoxes;
numberOfGiftBoxes = window.prompt
('Please enter now many boxes you are purchasing.', '');
numberOfGiftBoxes = parseFloat(numberOfGiftBoxes);
if (numberOfGiftBoxes <= 3)
{
document.write("no discount");
}
if (numberOfGiftBoxes >= 4) && (numberOfGiftBoxes <= 11)
{
document.write("5% discount");
}
if (numberOfGiftBoxes >= 12) && (numberOfGiftBoxes <= 29)
{
document.write("10% discount");
}
if (numberOfGiftBoxes >=30)
{
document.write("20% discount");
}
</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>
You're right. This should work:
<HTML>
<HEAD>
<TITLE>Volume Discount</TITLE>
<SCRIPT LANGUAGE = "JavaScript">
// A program to tell a customer what volume discount they can expect.
var numberOfGiftBoxes;
numberOfGiftBoxes = window.prompt
('Please enter now many boxes you are purchasing.', '');
numberOfGiftBoxes = parseFloat(numberOfGiftBoxes);
if (numberOfGiftBoxes <= 3)
{
document.write("no discount");
}
if (numberOfGiftBoxes >= 4 && numberOfGiftBoxes <= 11)
{
document.write("5% discount");
}
if (numberOfGiftBoxes >= 12 && numberOfGiftBoxes <= 29)
{
document.write("10% discount");
}
if (numberOfGiftBoxes >=30)
{
document.write("20% discount");
}
</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>
I am afraid this one does not prompt either.
Now this one prompts and works for no discount and 5 % discount
<HTML>
<HEAD>
<TITLE>Volume Discount</TITLE>
<SCRIPT LANGUAGE = "JavaScript">
//A program to tell a customer what volume discount they can expect.\
var numberOfGiftBoxes;
numberOfGiftBoxes = window.prompt
('Please enter how many boxes you are purchasing.', '');
numberOfGiftBoxes = parseFloat(numberOfGiftBoxes);
if (numberOfGiftBoxes <= 3)
{
document.write("no discount");
}
else
if (numberOfGiftBoxes >= 4 )
{
document.write("5% discount")
}
else
if (numberOfGiftBoxes <= 11)
{
document.write("5% discount")
}
else
if (numberOfGiftBoxes >= 12)
{
document.write("10% discount")
}
else
if (numberOfGiftBoxes <= 30)
{
document.write("10% discount")
}
if (numberOfGiftBoxes >30)
{
document.write("20% discount")
}
</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>
but if you type number in like 45 to prompt it displays 5%discount20%discount
I tested the last code I posted, and it works for me
Previously it did not work because it had errors in the IFs parenthesis.
Your code is only working for 0% and 5% discount because of this part:
if (numberOfGiftBoxes <= 3)
{
document.write(”no discount”);
}
else
if (numberOfGiftBoxes >= 4 )
{
document.write(”5% discount”)
}
Every quantity that is greater than 3 will fit into the >= 4 condition. If you want to do it that way you should start evaluating the highest numbers of gift boxes first
for example:
if (numberOfGiftBoxes >30)
{
document.write(”20% discount”)
}
else
if (numberOfGiftBoxes >= 12)
{
document.write(”10% discount”)
}
... etc
This one works, same as yours with brackets, many thanx
<HTML>
<HEAD>
<TITLE>Volume Discount</TITLE>
<SCRIPT LANGUAGE = "JavaScript">
// A program to tell a customer what volume discount they can expect.
var numberOfGiftBoxes;
numberOfGiftBoxes = window.prompt
('Please enter how many boxes you are purchasing.', '');
numberOfGiftBoxes = parseFloat(numberOfGiftBoxes)
if (numberOfGiftBoxes <= 3)
{
document.write("no discount")
}
else
if ( (numberOfGiftBoxes >= 4) && (numberOfGiftBoxes <= 11))
{
document.write("5% discount")
}
else
if ( (numberOfGiftBoxes >= 12) && (numberOfGiftBoxes <= 29))
{
document.write("10% discount")
}
else
if (numberOfGiftBoxes >= 30)
{
document.write("20% discount")
}
</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>
I like this idea, I have been working on modifying a code to suit my needs, but am having no luck, maybe you guys could help me with this, I need this code to do % calculations for multiple products, otherwise I need to post like 100 of this code in one page:
function processOrder()
{
var quantity = parseInt(document.frmOrder.txtQuantity.value);
var unitPrice, totalPrice;
// The unit price depends on the quantity order
// The higher the quantity, the lower the unit price
if( quantity < 5 )
unitPrice = 22.80;
else if( quantity < 10 )
unitPrice = 20.80;
else if( quantity < 15 )
unitPrice = 18.80;
else if( quantity < 20 )
unitPrice = 16.80;
else if( quantity < 25 )
unitPrice = 14.80;
else if( quantity < 30 )
unitPrice = 12.80;
else if( quantity < 35 )
unitPrice = 10.80;
else if( quantity < 40 )
unitPrice = 8.80;
else
unitPrice = 6.80;
totalPrice = quantity * unitPrice;
document.frmOrder.txtUnitPrice.value = unitPrice.toFixed(2);
document.frmOrder.txtTotalOrder.value = totalPrice.toFixed(2);
// Create Advanced Product string for InternetSecure Processor
document.frmOrder.Products.value = ""+ unitPrice +"::"+ quantity +"::VERSION 2010::Discounted lisenses::";
}
I want it to work in 10% intervals for bulk orders, for instance 1-4 no discount, 5-9 10%, 10-19 15%, 20+ 20%
is there any way you could help me out?
Free Guide: Managing storage for virtual environments
Complete a brief survey to get a complimentary 70-page whitepaper featuring the best methods and solutions for your virtual environment, as well as hypervisor-specific management advice from TechTarget experts. Don’t miss out on this exclusive content!
Discuss This Question: 10 Replies