Чтобы быть более конкретным, я пытаюсь сделать программу для расчета цены. Цена должна изменить, чем больше вы покупаете.Как установить переменную, которая изменяется в соответствии с другой переменной
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Transaction Invoice</title>
<meta name="author" content="Caprica" />
<!-- Date: 2014-11-12 -->
</head>
<body>
<script type="text/javascript">
// Program name: Transaction Invoice
// Purpose: To do a transaction
// Author: Ephraim Vickers
// Date last modified: Today
// Variables
var BREAK = "<br />"
var pricePound = 1.13; // This is the price per pound
var amountPurchased = 0; // Number of pounds purchased
var reducRate = parseInt (document.getElementById ("0.02").value); // This is the percent it is reduced
var noDiscount = pricePound * amountPurchased; //Cost without discount
var reducCost = noDiscount - amountSaved;
var amountSaved = noDiscount * reducRate;
document.write ("Hello and thank you for shopping at the ACME cement company. This program is here to handle transaction information and apply discounts. For all other concerns please go to our main site." + BREAK)
window.alert("Please be aware that all cement purchases are on sell and, the more you buy the more it will be discounted!!! All numbers inputted will be converted to pounds. Some restrictions and limitations do apply see a instore clerk for details.")
amountPurchased = prompt ("Valued customer, please enter the amount of cement you would like to purchase.");
noDiscount = pricePound * amountPurchased
reducCost = noDiscount - amountSaved
amountSaved = noDiscount * reducRate
parseFloat(reducRate)
if (amountPurchased <= 0) {
window.alert("ERROR. Your purchase is below our minimum purchase amount. Please refresh the page and increase the amount you are trying to purchase.");
}
if (amountPurchased <= 500) {
reduceRate = 0.02;
}
if (amountPurchased <=9000) {
reduceRate = 0.04;
}
if (amountPurchased <= 15000) {
reduceRate = 0.05;
}
if (amountPurchased >= 15000) {
reduceRate = 0.09;
};
document.write (amountSaved); // This also returns 0 but i think its because of the reducRate
document.write (reducRate); //This is the part that always returns 0
</script>
По какой-то причине lowerRate продолжает возвращать ноль. Как сделать изменение ставки с суммой. Извините, что не разместили все это
Мы должны видеть весь код. –
- глобальная переменная reduceRate? если вы не знаете /, чтобы убедиться, что замените его на window.reduceRate – TakeMeAsAGuest
Из этого кода, если 'amountPurchased' меньше, чем' 14,999', он всегда будет возвращать 'lowerRate' в' 0.05'. –