i have been writting javascript on visual studio code and the 'return keyword seems not to be working.the code is correct and should display sumOfCount on the console but instead it onlt displays 1..this is code for displaying the number of times an element appears in an array .
const numbers=[1,2,,2,3,4,5,1,];
const sumOfCount=countOccurence(numbers,2);
console.log (sumOfCount);
function countOccurence(array,searchElement){
let count=0;
for (let number of array)
if (number===searchElement);
count++;
return count;
}
hi remove semicolon from end of if statement. please refer below code
const numbers=[1,2,,2,3,4,5,1,];
const sumOfCount=countOccurence(numbers,2);
console.log (sumOfCount);
function countOccurence(array,searchElement){
let count=0;
for (let number of array)
if (number===searchElement)
count++;
return count;
}