0

How do I solve the Store Manager Code Project? See 44 CODE PROJECT under JavaScript for description.

Here is my code. It solves Test Case #1 but not Test Case #2 which is to increase each variable by 100. function main() { var increase = parseInt(readLine(), 10); var prices = [98.99, 15.2, 20, 1026]; //your code goes here for (var increase = 0; increase < prices.length; increase++) { prices[increase] += 9 } console.log(prices); }

7th Dec 2021, 1:09 AM
Mario Camarillo
3 ответов
+ 3
// try this 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);
7th Dec 2021, 1:52 AM
SoloProg
SoloProg - avatar
+ 1
It worked. Thank you.
7th Dec 2021, 11:02 AM
Mario Camarillo
0
We can do much better, we can just call a for loop telling to increase for each iteration of prices that it encounter to increase the price. function main() { var increase = parseInt(readLine(), 10); var prices = [98.99, 15.2, 20, 1026]; //your code goes here for(x in prices) //for each iteration in prices prices[x] += increase // do price + increase console.log(prices); }
31st Oct 2022, 12:27 PM
Filippo Cossu
Filippo Cossu - avatar