I am doing JavaScript courses and got stuck at this question.
Define a function named countLetters
that receives two parameters:
1) sentence - type: string
2) character - type: string
The function should return a count of every character
present in sentence
.
HINT: You can access a single character in a string just like accessing an element in an array - myString[3]
would access the third character
Here is what I have done so far.
function countLetters(sentence, character) {
for(let i=0; i <= sentence.length; i++) {
let count = character[i];
return sentence.match(count).length;
}
}
Thank you!