programming-examples/js/Functions/Write a JavaScript function that accepts two arguments, a string and a letter and the function will count the number of occurrences of the specified letter within the string..js
2019-11-15 12:59:38 +01:00

14 lines
322 B
JavaScript

function char_count(str, letter)
{
var letter_Count = 0;
for (var position = 0; position < str.length; position++)
{
if (str.charAt(position) == letter)
{
letter_Count += 1;
}
}
return letter_Count;
}
console.log(char_count('w3resource.com', 'o'));