+ 1

Hello, is the anyone who just started javascript and can maybe explain the Store manager problem...

Been trying multiple codes and none are running

26th May 2022, 8:00 AM
Nonhle Msomi
7 Antworten
+ 1
Share your attempt by saving it in playground.. Along with task description.. So that helps to identify problem and solution...
26th May 2022, 8:13 AM
Jayakrishna 🇮🇳
+ 1
function main() { var increase = parseInt(readLine(), 10); var prices = [98.99, 15.2, 20, 1026]; //your code goes here i=9; for (;i<prices.length;){ Prices[i] + increase; } console.log(prices); }
26th May 2022, 8:15 AM
Nonhle Msomi
0
This was my last attempt
26th May 2022, 8:16 AM
Nonhle Msomi
0
In your code, i=9; // what is this i do? for (;i<prices.length;){ // initially i<prices.length => 9<4 false so loop won't start. But, it missing updation of I value. you are not upading i value no where, so if it start then it's infinite loop.. And Prices[i] + increase; // this statement has no effect. Store the result in a variable to use it.. } console.log(prices); } What is your task here.. Mention it.. May you need increase item values by 9 ? Then just price[I] = price[I]+ 9; Loop from I =0 to price.length Revise topic of loops before it. Hope it helps..
26th May 2022, 8:28 AM
Jayakrishna 🇮🇳
0
Thank you for helping and explaining better for me
22nd Jun 2022, 3:05 AM
Nonhle Msomi
0
My solution. function main() { var increase = parseInt(readLine(), 10); var prices = [98.99, 15.2, 20, 1026]; //your code goes here prices[0] = 98.99 + increase; prices[1] = 15.2 + increase; prices[2] = 20 + increase; prices[3] = 1026 + increase; console.log(prices); }
5th Aug 2022, 1:01 PM
Oyindamola Abbatty
Oyindamola Abbatty - avatar
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:26 PM
Filippo Cossu
Filippo Cossu - avatar