这是我的代码。任何人都知道为什么没有输出吗?我没有发布语法错误,可以输入内容,但是输入后不显示任何输出或错误信息....... ................................................... ................................................... ................................................... .....
<script type="text/javascript">
<!--
var basePrice, carType, salePrice, markupLow, markupMed, markupHigh;
var fordLow = 1.02;
var fordMed = 1.03;
var fordHigh = 1.05;
var GMLow = 1.05;
var GMMed = 1.07;
var GMHigh = 1.10;
var dodgeLow = 1.01;
var dodgeMed = 1.02;
var dodgeHigh = 1.03;
var highCutoff = 20000;
var lowCutoff = 10000;
var errorFlag = 0;
basePrice = prompt("What is the base price?", "10000");
basePrice = parseInt(basePrice);
carType = prompt("Which car brand? ford, gm, dodge?", "ford");
switch(carType)
{
case "ford":
markupLow = fordLow;
markupMed = fordMed;
markupHigh = fordHigh;
break;
case "gm":
markupLow = gmLow;
markupMed = gmMed;
markupHigh = gmHigh;
break;
case "dodge":
markupLow = dodgeLow;
markupMed = dodgeMed;
markupHigh = dodgeHigh;
break;
default:
alert("You typed " + carType + " you needed to type: ford, gm, or dodge");
errorFlag = 1;
break;
if (errorFlag == 0)
{
if (basePrice > highCutoff)
{
markupRate = markupHigh;
}
else if (basePrice < lowCutoff)
{
markupRate = markupLow
}
else
{
markupRate = markupMed;
}
salePrice = basePrice * markupRate;
document.write("Base Price: $" + basePrice);
document.write("<br>Car Make" + carType);
document.write("<br>The sale price: $" + salePrice);
}
else
{
document.write("You typed " + carType + " you needed to type: ford, gm, or dodge");
}
}
// -->
</script>
您需要提前关闭switch语句。否则,由于的break
声明,其余的将不会执行default
。
var basePrice, carType, salePrice, markupLow, markupMed, markupHigh;
var fordLow = 1.02;
var fordMed = 1.03;
var fordHigh = 1.05;
var GMLow = 1.05;
var GMMed = 1.07;
var GMHigh = 1.10;
var dodgeLow = 1.01;
var dodgeMed = 1.02;
var dodgeHigh = 1.03;
var highCutoff = 20000;
var lowCutoff = 10000;
var errorFlag = 0;
basePrice = prompt("What is the base price?", "10000");
basePrice = parseInt(basePrice);
carType = prompt("Which car brand? ford, gm, dodge?", "ford");
switch (carType) {
case "ford":
markupLow = fordLow;
markupMed = fordMed;
markupHigh = fordHigh;
break;
case "gm":
markupLow = gmLow;
markupMed = gmMed;
markupHigh = gmHigh;
break;
case "dodge":
markupLow = dodgeLow;
markupMed = dodgeMed;
markupHigh = dodgeHigh;
break;
default:
alert("You typed " + carType + " you needed to type: ford, gm, or dodge");
errorFlag = 1;
break;
} // close switch
if (errorFlag == 0) {
if (basePrice > highCutoff) {
markupRate = markupHigh;
} else if (basePrice < lowCutoff) {
markupRate = markupLow
} else {
markupRate = markupMed;
}
salePrice = basePrice * markupRate;
document.write("Base Price: $" + basePrice);
document.write("<br>Car Make" + carType);
document.write("<br>The sale price: $" + salePrice);
} else {
document.write("You typed " + carType + " you needed to type: ford, gm, or dodge");
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句