表格中的总和计算

时间:2019-04-23 13:34:11

标签: javascript

我正在创建一个输出到HTML文档的表单。用户作为影响折扣应用的一些选项。我有小计工作,但折扣和总计工作不正常。折扣将输出一些值,但其他值不显示。

总计仅显示为NaN。

我尝试使用其他方法来计算总和,但没有任何运气


//The proceeding code calculated the sum based on the users selections

    //Variable that Displays the SubTotal before discount is applied
    var eltableSub = document.getElementById("tableSub")
    if (PropertyUsage == "Residential")
        eltableSub.textContent = "£ " + (90 * NumberOfRooms).toFixed(2);
    if (PropertyUsage == "Business")
        eltableSub.textContent = "£ " + (150 * NumberOfRooms).toFixed(2);
    //Variable that displays the discount
    var elDiscount = document.getElementById("tableDiscount")
        if (NumberOfRooms  <=5 & PropertyUsage == "Residential")
            elDiscount.textContent = '£ ' + (NumberOfRooms * 90).toFixed(2) + " No Discount applied"
        if ((NumberOfRooms >=6 & NumberOfRooms <=9) & PropertyUsage == "Residential")
            elDiscount.textContent = '£ ' + ((NumberOfRooms * 90) / 100 * 10).toFixed(2) + " (10%)"
        if ((NumberOfRooms >=10 & PropertyUsage == "Residential"))
            elDiscount.textContent = '£ ' + ((NumberOfRooms * 90) / 100 * 15).toFixed(2) + " (15%)"
        if  (NumberOfRooms  <=5 & PropertyUsage == "Business")
            elDiscount.textContent = '£ ' + (NumberOfRooms * 150).toFixed(2) + " No Discount applied"
        if ((NumberOfRooms >=6 & NumberOfRooms <=9) & PropertyUsage == "business")
            elDiscount.textContent = '£ ' + ((NumberOfRooms * 150) / 100 * 10).toFixed(2) + " (10%)"
        if  (NumberOfRooms >=10 & PropertyUsage == "Business")
            elDiscount.textContent = '£ ' + ((NumberOfRooms * 150) / 100 * 15).toFixed(2) + " (15%)" // Working!!!!

    // Variable that Displays the Total based on the number of rooms and the applicable discount
    var elTableTotal = document.getElementById('tableTotal')


} 

function ShowSum(){
var Summary = document.getElementById("SummaryTable")
Summary.style.display="block";
}

预期输出应显示SubTotal,Discount(作为值和字符串表示形式)和GrandTotal

0 个答案:

没有答案