I am working on a book and it is asking to create a function to find the spaces in a string. Not sure what I am doing wrong, but here is the code I have.
function calSpaces(str) {
var spaces = 0;
for(var i = 0; i < str.length; i++) {
if (str[i] === ' ') {
spaces ++;
}
return spaces - 1;
}
console.log(calSpaces("This is a test of spaces."));