multiplying the elements in parallel Arrays

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • joor
    New Member
    • Feb 2008
    • 3

    multiplying the elements in parallel Arrays

    Hi

    I am a beginner and currently trying to create a small program. I seem to be stuck on the multiplication of their elements. Eg. I have an Array with 4 different prices for 4 different products and have created 2 other Arrays to which I have assigned values through window.prompt(p arseFloat) , what I am trying to do is multiplicate the values on the parallel arrays by their corresponding indexes and keep a running total so I can have an overall total afterwards. Sorry if the explanation sounds poor.

    [CODE=javascript]var priceOfprod [12,14,2,45];

    var numberOfproduct s;
    numberOfproduct s = parseFloat(wind ow.prompt('how many different products you wish to purchase?','')) ;


    var orderProductArr ay = new Array (numberOfproduc ts)
    var orderQuantityAr ray = new Array (numberOfproduc ts)
    for (var count = 0; count < numberOfproduct s; count = count + 1)
    {
    indexOf = parseFloat(wind ow.prompt ('please enter item required',''));
    quantity = parseFloat(wind ow.prompt('how many units of this product do you required?','')) ;

    productPrices[indexOf] + '<br>')
    orderProductArr ay[count] = indexOf;
    orderQuantityAr ray[count] = quantity;
    };[/CODE]
    Last edited by acoder; Feb 25 '08, 07:40 AM. Reason: Added code tags
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Instead of parseFloat, use parseInt.

    Comment

    Working...