Can you help refine my function? I've created one that counts the number of 7s in an array, but it only counts each element once even if it has multiple 7s. How can I modify it to calculate the total number of 7s in the array without missing any? Please explain the solution in an easy-to-understand manner since I am new to JavaScript.
function sevenBoom(arr){
debugger;
let singleElement, string, includeSeven;
let flag = false;
let counter = 0;
for (let i=0; i<arr.length; i++){
singleElement = arr[i];
string = singleElement.toString();
includeSeven = string.includes("7");
if (includeSeven == true){
flag = true;
counter += 1;
}
}
if (counter == 0){
return "There is no 7 in the array";
}else{
return `Boom! There are ${counter} 7s in the array...`;
}
}
arr = [6,7,87, 777, 107777];
sevenBoom(arr);