+ 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
7 Answers
+ 1
Share your attempt by saving it in playground.. Along with task description.. So that helps to identify problem and solution...
+ 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);
}
0
This was my last attempt
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..
0
Thank you for helping and explaining better for me
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);
}
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);
}