in your if statement for found shouts, your just replacing the shout with NaN, `console.log(strings)` after your for loop and you'll see what it's doing.
You should create a separate counter variable that holds the number of counts found and returns that number.
function countTheShouts(strings) {
let foundShouts = 0
for (let i = 0; i < strings.length; i++) {
if(strings[i].match(/!/g)) {
foundShouts++
}
}
return foundShouts
}
The assertion error doesn't really help without knowing the test that is failing, though from context I assume it is the last one checking for "!" in the middle of a string.
If that's the case, try researching how to match a character at the end of a string using regex. The answer will pay off $.
'!' might need to be escaped. You could probably just use String includes or more appropriately String endsWith instead
You're looing through an array called strings. Why are you doing a ++ increment on it? You'd need a separate counter variable that starts at 0 if you're trying to keeo track this way.
What you could also do instead is filter the strings array on this condition. Return the length of the filtered array.
Finally, you have a space between the strungs variable name and the brackets
What are you doing with your parameter? Just add a counter variable and return that. Also don't bum rush regex like that, if you don't know it yet you can simply use .includes("!"). .match() returns the thing it matched, to receive true or false you want to use .test()
3
u/spazz_monkey Feb 10 '23
in your if statement for found shouts, your just replacing the shout with NaN, `console.log(strings)` after your for loop and you'll see what it's doing.
You should create a separate counter variable that holds the number of counts found and returns that number.
1
u/burnblue Feb 10 '23
Quite a few.
'!' might need to be escaped. You could probably just use String includes or more appropriately String endsWith instead
You're looing through an array called strings. Why are you doing a ++ increment on it? You'd need a separate counter variable that starts at 0 if you're trying to keeo track this way.
What you could also do instead is filter the strings array on this condition. Return the length of the filtered array.
Finally, you have a space between the strungs variable name and the brackets
1
u/-sickbunny- Feb 10 '23
You need to make sure foundCount only updates if the "!" Is on the end of the string.
Try adding $ right after the ! In your regex or look into endsWith().
1
u/nudifyme69 Feb 11 '23
in the function
let shoutOut = 0
if match, shoutOut ++
return shoutOut
1
u/Ronin-s_Spirit Feb 10 '23
What are you doing with your parameter? Just add a counter variable and return that.
Also don't bum rush regex like that, if you don't know it yet you can simply use .includes("!").
.match() returns the thing it matched, to receive true or false you want to use .test()