Advertisement
Timkor

nativeCity

Oct 14th, 2020 (edited)
2,316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let cities = []
  2. 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.
  3. cities [NameOfTheCity] = NameOfTheCity; // what do you expect this line to do?
  4. let x = 0 // cleaner
  5. while (x < 10) {
  6.     console.log (NameOfTheCity = prompt  ('Enter the name of the city or town'))
  7.     // you do the same ten times with one variable, instead of fill the array cities[x] = ...
  8.     // and wrap assignment into outer console.log is not mandatory
  9.      x++
  10. }
  11.  
  12. let NameOfTheNativeCity= prompt ('Enter your native city or town') //use previous declared variable NameOfTheCity
  13. if (cities [NameOfTheCity] == NameOfTheNativeCity) { // you checking only one array item (literally property, if be fully
  14.     // honest) try to console.log(cities [NameOfTheCity]). You need cycle again
  15.     // console.log ('Я знаю твой город!') // о , эту часть кода писал понимающий русский. Для заполнения массива используйте  
  16.     // цикл чтобы положить в каждую его ячейку введенный город, при этом промежуточную переменную использовать не
  17.     // обязательно. После того, как в отдельной переменной вы сохраните введенный родной город - вам снова нужно проверить
  18.     // все ячейки массива,что нужно?  Да-да, банальный цикл. Пока так. Таков путь. Потом, возможно , будете иначе проверять.
  19. } else {
  20.     console.log ('Я не знаю твой город')
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement