0

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 }

10th Feb 2022, 2:56 PM
Shaishab Chandra Shil
Shaishab Chandra Shil - avatar
6 Answers
+ 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) }
21st Feb 2022, 7:20 PM
Jackie
Jackie - avatar
+ 1
function main() { var increase = parseInt(readLine(), 10); var prices = [98.99, 15.2, 20, 1026]; for(var i=0;i<prices.length ;i++){ prices[i]+=increase; } console.log(prices); }
20th Jan 2023, 11:43 AM
VISHNUPRIYA S
VISHNUPRIYA S - avatar
0
My solution: function main() { var increase = parseInt(readLine(), 10); var prices = [98.99, 15.2, 20, 1026]; //your code goes here prices[0] = 98.99 + increase; prices[1] = 15.2 + increase; prices[2] = 20 + increase; prices[3] = 1026 + increase; console.log(prices); }
5th Aug 2022, 1:00 PM
Oyindamola Abbatty
Oyindamola Abbatty - avatar
0
function main() { var increase = parseInt(readLine(), 10); var prices = [98.99, 15.2, 20, 1026]; //your code goes here var pricesIn = prices.map(ajout) function ajout (value){ return value + increase ; } console.log(pricesIn) }
8th Feb 2023, 9:23 AM
Maya-Line PELAGE
- 1
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);
10th Feb 2022, 3:53 PM
Leo
Leo - avatar
- 2
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) }
7th Apr 2022, 7:02 AM
Nikola M.
Nikola M. - avatar