How do I make the output like an array with third brackets like [a+1,b+1,c+1]? My code is giving the output in different lines. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

How do I make the output like an array with third brackets like [a+1,b+1,c+1]? My code is giving the output in different lines.

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. My code: function main() { var increase = parseInt(readLine(), 10); var prices = [98.99, 15.2, 20, 1026]; //your code goes here for(var i =0;i<4;i++){ prices[i] += increase ; console.log(prices[i]); } }

29th Oct 2021, 10:46 AM
Rubayet Kamal
Rubayet Kamal - avatar
2 Answers
+ 3
Nvm I worked it out. My code in case anyone wonders where the issue was: function main() { var increase = parseInt(readLine(), 10); var prices = [98.99, 15.2, 20, 1026]; //your code goes here for(var i =0;i<4;i++){ prices[i] += increase ; } console.log(prices); }
29th Oct 2021, 10:59 AM
Rubayet Kamal
Rubayet Kamal - avatar
+ 3
In the first case u were printing the array content looping on each index. In your second case (solution) you are printing the array itself. So yeah! Congratz for solving this yourself
29th Oct 2021, 11:13 AM
Guillem Padilla
Guillem Padilla - avatar