Store Manager | Sololearn: Learn to code for FREE!

-1

Store Manager

You are working on a Store Manager program, which stores the prices in an array. You need to add functionality to increase the prices by the given amount. The increase variable is taken from user input. You need to increase all the prices in the given array by that amount and output to the console the resulting array. _____&_____ mycode _____&_____ function main() { var increase = parseInt(readLine(), 10); var prices = [98.99, 15.2, 20, 1026]; //your code goes here }

2/10/2022 2:56:31 PM

Shaishab Chandra Shil

3 Answers

New Answer

+3

function main() { var increase = parseInt(readLine(), 10); var prices = [98.99, 15.2, 20, 1026]; var sum = []; for(i = 0; i<prices.length; i++) { sum[i] = (prices[i] + increase); } console.log(sum) }

0

Use javascript map for that: const prices = [98.99, 15.2,20, 1026].map(price => price+increase); or copy the array into a new one: const newPrices = [...prices].map(price => price+increase);

0

function main() { var increase = parseInt(readLine(), 10); var prices = [98.99, 15.2, 20, 1026]; //your code goes here var pl = prices.length; for(i=0; i<pl;i++){ prices[i]+=increase } console.log(prices) }