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

14 lines
322 B
JavaScript
Raw Normal View History

2019-11-15 12:59:38 +01:00
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'));