我需要編寫一段代碼來請求合同年數的值。然後使用for循環計算每年2%的折扣係數,即如果是一年合同,價格將爲全價的98%,如果是兩年合同,價格將爲96%的全價,等等。計算每年2%的折扣係數
我似乎有點卡住,不知道我是否完全理解了他們的要求。
以下是我已經做了:提前任何幫助
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transition//EN" "http://www.w3.org/TR/xhtml/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<script type = "text/javascript">
var stringVariable = prompt ("Enter the number of people")
var numberVariable
var loopCounter = prompt ("How many years?");
var numberCount = new Array(100/2);
if (stringVariable <= 30) {
numberVariable = 15*stringVariable;
}
else if (stringVariable> 30 && stringVariable<60) {
numberVariable = 12*stringVariable;
}
else if (stringVariable>60) {
numberVariable =12*stringVariable;
}
alert ("Total cost is: $" + numberVariable);
for (loopCounter = 0; loopCounter <= 4; loopCounter++)
{
document.write("Total discount $" + loopCounter - numberCount[loopCounter] + "<br />");
}
alert ("Total cost is: $" + numberVariable - numberCount);
</script>
</body>
</html>
感謝。
這是功課? – j08691
兩年後,價格不會是原來的96%。這將是原來的96.04%。 – Isaac
無論你賣什麼,請註冊50年 –