I'm making a program that takes an array of links and returns how many are broken and how many are working. Right now, I'm testing it with an array that has four working links and two broken links. Here's my code:
function getBrokenLinks(linksArr){
let links = linksArr
let brokenLinks = 0
links.forEach(link => {
fetch(link.href)
.then( res => {
if ( res.status != 200 ){
brokenLinks++
}
}).then( () => {console.log(brokenLinks)})
})
return brokenLinks
}
and this is the output i receive:
I want the console to print the total of broken links only once, and after it has completed fetching all the links.