ybakun

2021/07/20 Юлія Бакун Задача про міста

Jul 20th, 2021
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Задача про міста
  2. // https://zero.p2p.shpp.me/tasks/4_0_goroda.html
  3.  
  4. function arrayIncludes(array, arrayLength, motherCity) { // створила функцію для знаходження збігів
  5.     for (let i = 0; i < arrayLength; i++) {
  6.         if (motherCity == array[i]) {
  7.             return true;
  8.         }
  9.     }
  10.     return false;
  11. }
  12. let array = new Array(5); // заповнила масив значеннями за допомогою циклу
  13. for (let i = 0; i < array.length; i++) {
  14.     let city = prompt("Введи назву міста " + (i + 1));
  15.     array[i] = city;
  16. }
  17. let arrayLength = array.length;
  18. let motherCity = prompt("Введи назву рідного міста");
  19. if (arrayIncludes(array, arrayLength, motherCity) == true) { // умова і виведення результатів в одному блоці
  20.     console.log("Я знаю твоє місто");
  21. } else if (arrayIncludes(array, arrayLength, motherCity) == false) {
  22.     console.log("Я НЕ знаю твоє місто");
  23. }
Advertisement
Add Comment
Please, Sign In to add comment