+ 2

The cycle does not pass three times

https://code.sololearn.com/W5zSb9hmu845/?ref=app It is necessary to ask a question three times and write the answers in an array.

4th Mar 2020, 3:24 PM
Anna/Аня
Anna/Аня - avatar
4 Respostas
+ 3
dont use i to store prompt input, just create a new one. or at least use let i, so i from the loop not modified
4th Mar 2020, 3:28 PM
Taste
Taste - avatar
+ 6
Taste it's worked, thank you🙂
4th Mar 2020, 3:30 PM
Anna/Аня
Anna/Аня - avatar
+ 3
var shopGoods = []; for(var i=0; i<=2; i++){ var x=prompt('Какой тип товаров продаете?'); shopGoods.push(x); } console.log(shopGoods); правильно так?
4th Mar 2020, 3:32 PM
Alexander Lebedev
Alexander Lebedev - avatar
+ 2
using same var name could work with let for(let i=0; i<=2; i++){ let i=prompt even though its working, it doesnt mean you should use it. for clarity purpose use different variable name like x in your new code
4th Mar 2020, 3:35 PM
Taste
Taste - avatar