Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/442.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript中的if语句_Javascript - Fatal编程技术网

javascript中的if语句

javascript中的if语句,javascript,Javascript,这是我的javascript类简介中的一个项目。以下是说明: 建筑师的费用按建筑成本的百分比计算。费用构成如下: 建筑物首个5000.00美元成本的8%。 如果余数大于零但小于或等于$80000.00,则添加余数的3%;如果余数大于$80000.00,则添加余数的2.5% 所以我让程序从这段代码开始,但是我该如何完成它呢 var totalCost; var architectFee; var architectPay; //prompt user to enter total cost of

这是我的javascript类简介中的一个项目。以下是说明:

建筑师的费用按建筑成本的百分比计算。费用构成如下: 建筑物首个5000.00美元成本的8%。 如果余数大于零但小于或等于$80000.00,则添加余数的3%;如果余数大于$80000.00,则添加余数的2.5%

所以我让程序从这段代码开始,但是我该如何完成它呢

var totalCost;
var architectFee;
var architectPay;

//prompt user to enter total cost of building
totalCost = prompt("What is the total cost of the building?");

//Output architect pay
if (totalCost <= 5000) {
  architectFee = 0.08
  architectPay = totalCost * architectFee;
  document.write("For a building that will cost $" + totalCost + "," + "the architect's pay will be $" + architectPay);
}

如果总成本等于或小于5000,或者如果总成本大于5000,则可以用一种方法计算成本。如果小于5000,则只需进行一次计算。如果大于5000,则需要取余数,并根据其大于或小于80000,对余数应用不同的百分比。这里是一个如何工作的粗略布局

var totalCost;
var architectFee;
var architectPay;

//prompt user to enter total cost of building
totalCost = prompt("What is the total cost of the building?");

//Output architect pay
if (totalCost <= 5000) {
  architectFee = 0.08
  architectPay = totalCost * architectFee;
  document.write("For a building that will cost $" + totalCost + "," + "the architect's pay will be $" + architectPay);
}
else{
  var architectPay = 0.08 * 5000;
  var remainder = totalCost - 5000;
  if(remainder <= 80000){
    architectPay = architectPay + (remainder * 0.03);
  }
  else if(remainder > 80000){
    architectPay = architectPay + (remainder * 0.025);
  }
  document.write("For a building that will cost $" + totalCost + "," + "the architect's pay will be $" + architectPay);
}

你需要的是打开一些JavaScript书籍并开始学习:首先检查它是否超过8万美元,如果超过5万美元,否则我不会说这完全是一个JS问题,因为考虑到成本的解释方式,我需要重新审视一下。以与税阶结构相同的方式更清楚地重新表述成本结构:如果成本>85000,则费用为275+.025*成本;否则,如果成本>5000,则费用为250+0.03*成本;否则,成本是.08*成本,因为您似乎知道if中的运算符,其余的基本上是基本的。。。基本的数学