1

我无法弄清楚我一直陷入循环。我不知道我是否有我的计算或是否在正确的区域中声明,请我可以使用一些帮助。我的输出就像是一天结束的报告。我真的可以使用帮助。

<script type="text/javascript">
<!--
// assignments
var cost, nachosCounter, moneyCollected, nachosRate, corndogRate, hotdogRate;
var hamAccum, hotdogAccum, corndogAccum, nachosAccum, hamburgerRate;
var beginDay, orderType, hamCounter, hotdogCounter, corndogCounter;
var totalHotdog, totalNachos, totalCorndog, totalHamburger, moneyCollected;    
var hamburgerRate = 4;
var hotDogRate = 2;
var cornDogRate = 3;
var nachosRate = 5;
var hamCounter = 0;
var hotdogCounter = 0;
var corndogCounter = 0;
var nachosCounter = 0;
var beginDay = "yes"
//initalizing loop
beginDay = "yes"
//start loop
while (beginDay == "yes")
{
    orderType = prompt("hamburger, hotdog, corndog, nachos", "");
    if (orderType == "hamburger")
    {
        hamCounter = hamCounter + 1;
        if (hamCounter == 1) 
        {
            hamAccum = "<br>The total number of hamburgers purchased: " + hamCounter;
        }
        else
        {
            hamAccum = hamAccum + "<br>" + hamCounter;
        }
    }
    else if (orderType == "hotdog")
    {
        hotdogCounter = hotdogCounter + 1;
        if (hotdogCounter == 1) 
        {
            hotdogAccum = "The total number of hotdog purchased:<br>" + hotdogCounter;
        }
        else
        {
            hotdogAccum = hotdogAccum + "<br>" + hotdogCounter;
        }
    }
    if (orderType == "corndog")
    {
        corndogCounter = corndogCounter + 1;
        if (corndogCounter == 1) 
        {
            corndogAccum = "<br>The total number of corndogs purchased: <br>" + corndogCounter;
        }
        else
        {
            corndogAccum = corndogAccum + "<br>" + corndogCounter;
        }
    }
    if (orderType == "nachos")
    {
        nachosCounter = nachosCounter + 1;
        if (nachosCounter == 1) 
        {
            nachosAccum = "<br>The total number of nachos purchased: <br>" + nachosCounter;
        }
        else
        {
            nachosAccum = nachosAccum + "<br>" + nachosCounter;
        }
    }
totalHotdog = hotdogCounter*hotDogRate;
totalHamburger = hamCounter*hamburgerRate;
totalCorndog = corndogCounter*cornDogRate;
totalNachos = nachosCounter*nachosRate;
moneyCollected = totalNachos+totalCorndog+totalHamburger+totalHotdog;
    beginDay = prompt("More to add?", "yes");
} 
//output
document.write(hotdogAccum);
document.write(hamAccum);
document.write(corndogAccum);
document.write(nachosAccum);
document.write("<br>The total dollar amount for hotdog: $ " + totalHotdog);
document.write("<br>The total dollar amount for hamburger: $ " + totalHamburger);
document.write("<br>The total dollar amount for corndogs:  $" + totalCorndog);
document.write("<br>The total dollar amount for nachos:  $" + totalNachos);
document.write("The total amount of money collected:  $" + moneyCollected);

// -->
</script>
4

0 回答 0