 JAVASCRIPT: Store Manager | Sololearn: Learn to code for FREE!

+1

# JAVASCRIPT: Store Manager

In JavaScript course, under Core Objects > 44 Code Project. You need to write a store manager program wherein you need to increase the price (in an array) depending on user's input. So the user's input will increase each price in that array. I could say that I was able to get the logic behind it but the problem is, it is actually different to the expected output. Here's my program below: function main() { var increase = parseInt(readLine(), 10); var prices = [98.99, 15.2, 20, 1026]; //your code goes here for (var i = 0; i < prices.length; i++) { console.log(prices[i] + increase); } } Sample User Input: 9 My Output: 107.99 24.2 29 1035 Expected Output: [ 107.99, 24.2, 29, 1035 ] I can't seem to display it in a single line.

0

Rolly U. Valdemoro Jr. Don't print each value just increase price and finally print array prices for (var p in prices) { prices[p] = prices[p] + increase; } console.log(prices);

+1

Rolly U. Valdemoro Jr. Hi Rolly, you need to store the values of incremented price to the price variable & then console log it out of the loop. So, it would be price = price[i] + increase & then console.log price out of the for loop

+1

Same solution, but using while loop function main() { var increase = parseInt(readLine(), 10); var prices = [98.99, 15.2, 20, 1026]; //your code goes here var x=0 while (x<prices.length) { prices[x] += increase x++ } console.log(prices) }

0

Thanks for the help, my bad. So I just have to store it in the variable first and the console log should be outside my for loop. I have the correct output now, I appreciate all the help. Regards, Rolly

0

for (x = 0; x < prices.length; x++) { prices[x] += increase; } console.log(prices);

0

Hello. Here is my solution. function main() { var increase = parseInt(readLine(), 10); var prices = [98.99, 15.2, 20, 1026]; //your code goes here var sum = []; for(i = 0; i<prices.length; i++) { sum[i] = (prices[i] + increase); } console.log(sum) }