44 Code Project: Store Manager | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

44 Code Project: 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. // Help, please. My code outputs an array without adding the number that’s input. https://code.sololearn.com/c27NnRbZkKSf/?ref=app

2nd Feb 2022, 3:05 AM
Tahiti🌍Castillo
Tahiti🌍Castillo - avatar
8 Answers
+ 3
Cristian Gabriel Mazzulla Rupali Thank you for this guidance! I followed the advice one step at a time. I used this: var i; for (i=0; i<prices.length; i++){ prices[i]= (prices[i]+ increase); } console.log(prices); // for the 🎖
2nd Feb 2022, 4:41 AM
Tahiti🌍Castillo
Tahiti🌍Castillo - avatar
+ 3
Rupali I always wondered why the code playground never indicates when your program runs correctly. It always just says No Output.
2nd Feb 2022, 4:49 AM
Tahiti🌍Castillo
Tahiti🌍Castillo - avatar
+ 2
First, in that code you share, there was a missing } at the end Second, the for condition doesn't make sense, you must compare i against the number of elements in your array Third, you are not accessing the array elements, you must access each of them to modify them https://www.sololearn.com/Course/JavaScript/1239/?ref=app https://www.sololearn.com/Course/JavaScript/1241/?ref=app
2nd Feb 2022, 4:24 AM
CGM
CGM - avatar
+ 2
Cristian Gabriel Mazzulla I called main() bcz when you run code in sololearn's playground it won't get executed, but when you're submitting in code coach then no need of calling main(). I used new array for simplicity sake...And the last I don't know.
2nd Feb 2022, 4:45 AM
Rupali Haldiya
Rupali Haldiya - avatar
+ 2
Rupali you're right, in the playground you have to call it. Why do you need to call it there but not when you submit it??🤨
2nd Feb 2022, 4:58 AM
CGM
CGM - avatar
+ 1
function main() { var increase = parseInt(readLine(), 10); var prices = [98.99, 15.2, 20, 1026]; //your code goes here var result = []; for (let i=0; i<prices.length; i++){ result[i] = prices[i] + increase; } console.log(result); } main()
2nd Feb 2022, 4:29 AM
Rupali Haldiya
Rupali Haldiya - avatar
+ 1
Rupali You don't need to call main, you don't need a new array, and no one needs the answer but the explanation.
2nd Feb 2022, 4:35 AM
CGM
CGM - avatar
+ 1
Cristian Gabriel Mazzulla code coach calls main() by its own but if you change function name main() to something else you have to call this manually else it won't work. 😅😅
2nd Feb 2022, 5:08 AM
Rupali Haldiya
Rupali Haldiya - avatar