Regular exp ,matching single character

Regular expression, Matching all single characters ,vowels
My program is giving the right result .But freecodecamp is throwing error
this is my pgm
let quoteSample = “Beware of bugs in the above code; I have only proved it correct, not tried it.”;

var vcount=0;

let vowelRegex = /[aeiou]/i; // Change this line

for (var i=0;i<quoteSample.length;i++)

{

let result = quoteSample[i].match(vowelRegex); // Change this line

console.log(result);

if(quoteSample[i].match(vowelRegex))vcount++;

}

console.log(vcount);

The error its showing–

Cannot read property ‘length’ of null

Cannot read property ‘length’ of null

Cannot read property ‘join’ of null
its telling have to count 25 vowels-
my pgm is counting 25 vowels and not counting any consonants

https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/regular-expressions/match-single-character-with-multiple-possibilities/

@pree you dont need to loop the match method has that built in for you .

yes…, got it now. hadn’t used /g
thanks @kravmaguy @camperextraordinaire

1 Like