What is the mistake in this java script code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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); }

9th Apr 2022, 10:38 AM
Achraf Soua
2 Answers
0
your condition should be less than the length of the array i <= prices.length
9th Apr 2022, 11:06 AM
Faisal Issaka
Faisal Issaka - 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:27 PM
Filippo Cossu
Filippo Cossu - avatar