I am trying to write a function that counts the number of punctuation in a sentence . but the function is not working.
here is the Instruction:
You should count the number of punctuations now.
Create a getPunctuationCount
function with a sentence
parameter.
Inside the function, create a loop to count the number of punctuation characters in the sentence
that will be passed into the function when it is called. For our purposes, a punctuation character is any character that is not a space (" "
) or a letter.
Your getPunctuationCount
function must return a number.
here is my code:
function getPunctuationCount(sentence){
let count = 0
let space = " "
let letter = "bcdfghjklmnpqrstvwxyzaeiou"
for(const punctuation of sentence){
if(punctuation !== letter && punctuation !== space){
count++;
}
}
return count;
}
getPunctuationCount("What's going on here?")
getPunctuationCount("What????!")