Hi,
you're missing a "return" for the recursive function call. Without that, the whole recursion doesn't work, because the final value doesn't get passed on. The "original" function call simply returns nothing, so you end up with "undefined".
There are several other logical errors and Javascript mistakes:
Code:
splitArray + toScramble[index];
This line by itself doesn't do anything, because it's an expression like "1 + 1". Without an assignment, it's just discarded. The value of the expression also isn't correct, because you add a string to an array. This yields a nonsense string like "ab,def". I guess you meant something like this:
Code:
splitArray.push(toScramble[index]);
However, there's a logical error: When the split character occurs multiple times and you only add it once at the end, all the characters except one get lost.
It might be a good idea to start with a simpler recursive function to understand the concept. A classical example would be the
factorial function: fac(n) = 1 * 2 * ... *n
Code:
function fac(n) {
if (n == 0)
return 1; // base case
else
return n * fac(n - 1); // recursive call
}
You can also try to recursively revert an error.