Hello
Code:
count = 0;
var i = 0;
function howManySpaces(input)
{
while(i < input.length-1){
if {(howManySpaces[index] = '')
count++;
i++ }
else {
i++ }
}
}
I think the next part is completly wrong
Code:
if {(howManySpaces[index] = '')
- There is no argument for the "if". if (arguments) {code to excute}.
-There is no array named "howManySpaces".
- "index" is undefined.
-'' indicate empty. Space ' '.
I think the code could be something like:
Code:
var count = 0;
var i = 0;
function howManySpaces(n) {
while(i < n.length-1){
if (n[i] = ' '){
count++;
i++ ;}
else {
i++ ;}
}
return count;
}
spaces= howManySpaces(input);
But maybe it's better to use regular expression to test agains all white spaces.
Something like:
Code:
var spaceChar= new RegExp ('\\s');
if (spaceChar.test(n[i]) {
...
Bookmarks