如何循环这些提示?我需要问5名员工他们的名字,然后是他们的月销售额

时间:2016-09-28 19:08:56

标签: javascript loops variables

  

如果我运行程序并在提示框中输入“John”和“15000”,则警告框中会显示“John这个月的工资是$ 1,5000undefined”。由于某种原因,该计划不考虑奖金。警告框应显示为“约翰你这个月的工资是2,500美元。”

<script>
var EmployeeName, EmployeeSales, Bonus, Commission;
/* The employee's bonus depends on the information they enter in the prompt box*/
if(EmployeeSales < 1001) {
Bonus= 0;
}
else if(EmployeeSales > 1000 && EmployeeSales <10001) {
Bonus= 100;
}
else if(EmployeeSales > 10000) {
Bonus= 1000;
}

/*These prompt boxes get information from the user in order to calculate their bonus & commission*/
for(i=0; i <= 5; i++) {
EmployeeName = prompt("Please enter your name.");
EmployeeSales = prompt("Please enter your monthly sales");
alert(EmployeeName + " your salary this month is" + " $" + 
(EmployeeSales * 0.1) + Bonus);
}
</script>

2 个答案:

答案 0 :(得分:1)

这应该适合你:

customerService.getConfig().setLogin("login");

答案 1 :(得分:0)

最简单的,并且遵循现有代码的风格,就是问员工是否想要计算他的工资并进行递归调用:

// Wrap it all inside a function
function askEmployee() {
    // Current code
    var EmployeeName, EmployeeSales, Bonus, Commission;
    EmployeeName = prompt("Please enter your name.");
    EmployeeSales = prompt("Please enter your monthly sales");
    alert(EmployeeName + " your salary this month is" + " $" + EmployeeSales);

    // Ask if should calculate new salary or not, and act accordingly
    var askAgain = confirm("Do you want to calculate your salary for this month?")
    if ( askAgain ) {
        askEmployee();
    }
    else {
        return false
    }
}

// Then call it for the first time
askEmployee()