Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let cities = []
- let NameOfTheCity // suggest a better name: let nativeCity, UPD just now i am figure out, what do you mean. Ok, you can use that variable NameOfTheCity , despite she is redundant. But eventually entered city name must contained to array item.
- cities [NameOfTheCity] = NameOfTheCity; // what do you expect this line to do?
- let x = 0 // cleaner
- while (x < 10) {
- console.log (NameOfTheCity = prompt ('Enter the name of the city or town'))
- // you do the same ten times with one variable, instead of fill the array cities[x] = ...
- // and wrap assignment into outer console.log is not mandatory
- x++
- }
- let NameOfTheNativeCity= prompt ('Enter your native city or town') //use previous declared variable NameOfTheCity
- if (cities [NameOfTheCity] == NameOfTheNativeCity) { // you checking only one array item (literally property, if be fully
- // honest) try to console.log(cities [NameOfTheCity]). You need cycle again
- // console.log ('Я знаю твой город!') // о , эту часть кода писал понимающий русский. Для заполнения массива используйте
- // цикл чтобы положить в каждую его ячейку введенный город, при этом промежуточную переменную использовать не
- // обязательно. После того, как в отдельной переменной вы сохраните введенный родной город - вам снова нужно проверить
- // все ячейки массива,что нужно? Да-да, банальный цикл. Пока так. Таков путь. Потом, возможно , будете иначе проверять.
- } else {
- console.log ('Я не знаю твой город')
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement