Calculate the loss incurred in selling the given items at discounted price | Function to return the x % of n ; Function to return the total loss ; To store the total loss ; Original price of the item ; The price at which the item will be sold ; The discounted price of the item ; Loss incurred ; Driver code ; Total items
function percent ( n , x ) { let p = n * x ; p = Math . floor ( p / 100 ) ; return p ; } function getLoss ( price , quantity , X , n ) { let loss = 0 ; for ( let i = 0 ; i < n ; i ++ ) { let originalPrice = price [ i ] ; let sellingPrice = originalPrice + percent ( originalPrice , X [ i ] ) ; let afterDiscount = sellingPrice - percent ( sellingPrice , X [ i ] ) ; loss += ( ( originalPrice - afterDiscount ) * quantity [ i ] ) ; } return loss ; } let price = [ 20 , 48 , 200 , 100 ] ; let quantity = [ 20 , 48 , 1 , 1 ] ; let X = [ 0 , 48 , 200 , 5 ] ; let n = X . length ; document . write ( getLoss ( price , quantity , X , n ) ) ;