0

Help me with the code-project in javascript-intermediate

I have been stuck in the problem Store Manager function main() { var increase = parseInt(readLine(), 10); var prices = [98.99, 15.2, 20, 1026]; //your code goes here for(let i =0;i< prices.length;i++){ prices[i]+=increase; console.log(prices[i]); } } The topic said to add functionality to increase the prices by the given amount. Your Output 107.99 24.2 29 1035 Expected Output [ 107.99, 24.2, 29, 1035 ]. How to display like the `Expected Output`. Please help me. Thank you

20th Mar 2023, 8:13 AM
Minh Lưu
Minh Lưu - avatar
2 Answers
+ 1
Ah the solution is to take the console.log out of the loop and replace`[i]`
20th Mar 2023, 8:17 AM
Minh Lưu
Minh Lưu - avatar
+ 1
// It is a bit advance but here you go. function main() { var increase = parseInt(readLine(), 10); let prices = [98.99, 15.2, 20, 1026]; //your code goes here return prices.map(num => num + givenValue) } console.log(main()) //working with arrays become very easy if you know the some of the major array methods. // Here is a link to a YouTube Video, which is a must watch to learn how to work with arrays like pro, // https://www.youtube.com/watch?v=R8rmfD9Y5-c&ab_channel=WebDevSimplified
25th Mar 2023, 9:30 AM
Harman Maan
Harman Maan - avatar