Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Задача про міста
- // https://zero.p2p.shpp.me/tasks/4_0_goroda.html
- function arrayIncludes(array, arrayLength, motherCity) { // створила функцію для знаходження збігів
- for (let i = 0; i < arrayLength; i++) {
- if (motherCity == array[i]) {
- return true;
- }
- }
- return false;
- }
- let array = new Array(5); // заповнила масив значеннями за допомогою циклу
- for (let i = 0; i < array.length; i++) {
- let city = prompt("Введи назву міста " + (i + 1));
- array[i] = city;
- }
- let arrayLength = array.length;
- let motherCity = prompt("Введи назву рідного міста");
- if (arrayIncludes(array, arrayLength, motherCity) == true) { // умова і виведення результатів в одному блоці
- console.log("Я знаю твоє місто");
- } else if (arrayIncludes(array, arrayLength, motherCity) == false) {
- console.log("Я НЕ знаю твоє місто");
- }
Advertisement
Add Comment
Please, Sign In to add comment