// Программа поиска операторов мобильной связи Украины "use strict"; // Создаем объект с значениями ключей-массивами(коды операторов) var mobile = { Kyivstar: ["039", "067", "068", "096", "097", "098"], Vodafone: ["050", "066", "095", "099"], Lifecell: ["063", "093"], Intertelecom: ["094"], PEOPLEnet: ["092"], TriMob: ["091"] } // Запрашиваем у пользователя номер мобильного телефона var user = prompt("Введите номер мобильного телефона в формате: 000 1112233", ""); // Получаем доступ к первым 3-м индексам user var x = user.substr(0, 3); // Прогоняем в цикле все ключи for (var key in mobile) { var arr = mobile[key]; // Проходимся по всем массивам var check = arr.forEach(function (item, i, arr) { if (x === item) { //Выводим пользователю результат alert("Вас приветствует " + key); } }); } The task was this:
Create an object that contains the names and codes of mobile operators. The user enters a phone number and receives information about his operator.
I am not quite sure about the correctness of the solution to this problem.
It seems everything works, but is it right?