while(userInput!= -1)
{
var total=0.0;
var totalEarnings=0;
var item;
//var userInput;
var salesPerson=1;
var userInput= parseInt(prompt("outsidePlease enter noOfItemsSold of Item# 1 sold for SalesPerson #"+salesPerson+"\n"+" OR -1 to Exit "));
salesPerson++;
//alert("in while "+salesPerson);
//userInput= parseInt(prompt("Please enter noOfItemsSold of Item# "+item+" sold for SalesPerson #"+salesPerson+"\n"+" OR -1 to Exit "));
//if(userInput!=-1)
//{
for(item=2;item<5;item++)
{
//userInput= parseInt(prompt("Please enter noOfItemsSold of Item# "+item+" sold for SalesPerson #"+salesPerson+"\n"+" OR -1 to Exit "));
//var noOfItemsSold = parseInt( userInput);
if ( item == 1 )
{
total += userInput * 239.99;
}
else if (item == 2 )
{
total += userInput * 129.75;
}
else if ( item == 3 )
{
total += userInput * 99.95;
}
else if ( item == 4 )
{
total += userInput * 350.89;
}
var input= parseInt(prompt("Please enter noOfItemsSold of Item# "+item+" sold for SalesPerson #"+salesPerson+"\n"+" OR -1 to Exit "));
}
totalEarnings = .09 * total + 200;
document.writeln( "<h1>SalesPerson#"+salesPerson+" Total Earnings this week is " +totalEarnings +"</h1>" );
}
我正在尝试运行连续循环。脚本正在计算销售人员的总收入,我想运行脚本直到用户输入-1。我不知道我做错了什么,但这不起作用。我怎样才能解决这个问题?