Promise.all(
URL.map(
(url) => fetch(url)
.then((response) => `${url} : ${response.status} ${response.statusText}`)
.catch((e) => `${url} : ${e.message}`),
),
)
.then(
(results) =>
alert(results.join("\n")),
);
var unresolved = URL.length;
var results = [];
for (i = 0; i < URL.length; i += 1) {
(function(i) {
var request = new XMLHttpRequest();
request.open("GET", URL[i]);
request.onreadystatechange = function (event) {
console.log(request);
if (request.readyState === 4) {
if (request.status === 200) {
results[i] = URL[i] + ' РАБОТАЕТ';
} else {
results[i] = URL[i] + ' НЕ РАБОТАЕТ';
}
unresolved -= 1;
console.log(unresolved);
if (unresolved === 0) {
alert(results.join("\n"));
}
}
}
request.send();
})(i);
}