0

所以我知道我把它弄得乱七八糟,但它应该可以工作。我唯一的问题是我的 homeValue 输入没有得到返回值。因此,我的任何税款都不能适用。这是原始的问题陈述:

附言。很抱歉前几天直接问这个问题,我把我的闪存驱动器留在家里,这周晚些时候到期,所以我想今天把它贴出来。

你被要求为三县地区编写一个财产税程序。如果您住在查尔斯顿县,那么如果房屋价值低于或等于 50,000 美元,则您欠房屋价值的 1%。如果超过 50,000 美元但不超过 150,000 美元,您欠 1.50%,如果超过 150,000 美元,则欠 2%。如果您住在多切斯特县,那么如果低于或等于 50,000 美元,您就欠您房屋价值的 1.25%。如果超过 50,000 美元但不超过 150,000 美元,您欠 1.50%,如果超过 150,000 美元,则欠 1.75%。如果您住在伯克利县,那么如果房屋价值低于或等于 50,000 美元,则您欠 2%,如果大于 50,000 美元但不超过 150,000 美元,则为 2.25%,如果大于 150,000 美元,则为 2.75%。

在计划结束时,他们想查看房屋的价值、居住的县以及所欠的财产税。在代码中选择县时,必须使用 Switch 逻辑。

<script type="text/javascript">
<!--

//assumptions
var lowValue = 50000;
var medValue = 150000;
var highValue, taxCode, valueCode;
var charleston1 = .01;
var charleston2 = .015;
var charleston3 = .02;
var dorchester1 = .0125;
var dorchester2 = .015;
var dorchester3 = .0175;
var berkeley1 = .02;
var berkeley2 = .0225;
var berkeley3 = .0275;
var county, taxOwed, tax;
var charleston, dorchester, berkeley;
var homeValue = 0;

//input
homeValue = prompt("How much is the property worth?","");
homeValue = parseInt(homeValue);
county = prompt("Which county do you live in?", "");

//calculations

 switch (county)
 {
    case "charleston":
     taxCode = charleston;
     break;
    case "dorchester":
        taxCode = dorchester;
        break;
    case "berkeley":
        taxCode = berkeley;
        break;
    default:
                    alert("You didnt enter a proper county.");
                    break;  
 }    
switch (homeValue)
{
 case (homeValue):
            valueCode = lowValue;
            break;
 case (homeValue <= medValue):
            valueCode = medValue;
            break;
 case (homeValue > medValue):
            valueCode = highValue
 default:

                 break;
}           

switch (taxCode)
{
             case (charleston && lowValue):
             homeTax = charleston1;
             break;
             case (charleston && medValue):
             homeTax = charleston2;
             break;
             case (charleston && highValue):
             homeTax = charleston3;
             break

             case (dorchester && lowValue):
             homeTax = dorchester1;
             break;
             case (dorchester && medValue):
             homeTax = dorchester2
             break
             case (dorchester && highValue):
             homeTax = dorchester3
             break;

             case (berkeley && lowValue):
             homeTax = berkeley1;
             break;
             case (berkeley && medValue):
             homeTax = berkeley2;
             break;
             case (berkeley && highValue):
             homeTax = berkeley3;
             break;
             Default:
             alert("somethings wrong");
}    
totalTax = homeValue * homeTax;


//output
document.write("$" + homeValue + " house in " + county + " County.");
document.write("Tax owed: $" + totalTax);

// -->
</script>
4

1 回答 1

0
var county, homeValue, taxOwed;

//input
homeValue = prompt("How much is the property worth?","");
homeValue = parseInt(homeValue);
county = prompt("Which county do you live in?", "");

switch (county)
{
    case "charleston":
    if (homeValue <= 50000) {
        taxOwed = homeValue * 0.01;    
    }
    else if (homeValue > 50000 && homeValue < 150000) {
        taxOwed = homeValue * 0.015;
    }
    else {
        taxOwed = homeValue * 0.02;
    }
    break;

    case "dorchester":
    if (homeValue <= 50000) {
        taxOwed = homeValue * .0125;    
    }
    else if (homeValue > 50000 && homeValue < 150000) {
        taxOwed = homeValue * 0.015;
    }
    else {
        taxOwed = homeValue * 0.0175;
    }
    break;

    case "berkeley":
    if (homeValue <= 50000) {
        taxOwed = homeValue * 0.02;    
    }
    else if (homeValue > 50000 && homeValue < 150000) {
        taxOwed = homeValue * 0.0225;
    }
    else {
        taxOwed = homeValue * 0.0275;
    }
    break;

    default:
        alert("You didnt enter a proper county.");
        break;  
}    



//output
alert("Your house in " + county + " has a value of $" + homeValue + " and tax owed is $" + taxOwed);
于 2013-11-13T14:22:20.593 回答