+ 1

How can I make this code work?

How can I make this code work? https://code.sololearn.com/W24i0AC0Wqgl/?ref=app

2nd Apr 2022, 11:30 PM
صلاح الدين حلواني
4 Answers
+ 3
صلاح الدين حلواني You can even do without loop using includes function like this: if(maincities.includes(city)) { document.write("your city is from the main cities.") } else { document.write("your city is not from the main cities.") }
3rd Apr 2022, 2:34 AM
A͢J
A͢J - avatar
+ 2
I use console.log and change for loop little bit, so now it check length of your maincities. And add one more console lot to track how for loop work. https://code.sololearn.com/W1NnuQHF9Sdz/?ref=app
3rd Apr 2022, 12:50 AM
PanicS
PanicS - avatar
+ 2
Your problem is exualy with using i+1 in for loop, so use i++. i++ is exualy i = i + 1, so now you see where is problem, you never set this part i = You need to use i = i + any number, or if you add just one then you can use just i++
3rd Apr 2022, 12:59 AM
PanicS
PanicS - avatar
+ 1
Thank you Serbian.
3rd Apr 2022, 2:10 AM
صلاح الدين حلواني