0
What is the mistake in this java script code
function main() { var increase = parseInt(readLine(), 10); var prices = [98.99, 15.2, 20, 1026]; //your code goes here for(i=0;i>=prices.length ;i++){ prices=prices [i] +increase; } console.log(prices); }
2 Antworten
0
your condition should be less than the length of the array
i <= prices.length
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);
}