Image

Imagenathanmm wrote in Imagejavascript

Listens: Elliott Smith - Needle in the Hay

Help Again please

I'm having issues with getting everything to total up right. Any suggestions would help. It's only multiplying the last price by the last amount. Thanks. Nathan M

<SCRIPT LANGUAGE = "JavaScript"> /* This code takes input from user, adds it all up and gives a total at the bottom

         * of all the products for seven days and the corresponding value of them all */





  var retail_price, validInput = true, counter = 1, total = 0, amount_sold = 0, total_retail_value = 0;



  while (counter < 8) {

  pro_num = window.prompt ("Enter a product number (1-5)", "0");

  

  

  

  

  switch (pro_num) {

   case "1":

    price = 2.98;

    break;

   case "2":

    price = 4.50;

    break;

   case "3":

    price = 9.98;

    break;

   case "4":

    price = 4.49;

    break;

   case "5":

    price = 6.87;

    break;

   default:

    validInput = false;

   }

  if ( validInput == true) {

    amount_sold = window.prompt("Enter number of products sold", "0");}

    counter++;

  }

  



    document.writeln("Total Retail Value of all products sold over 7 days equals: " + ( amount_sold * price));

  



  









</SCRIPT>