Hello,
So this is my first attempt at this algorithm and I’ve done a bit of work with recursion in Java (not javascript) and I figured I would give it a go. My script appears to work in as much that it returns the correct results, but FCC won’t let it pass any of the tests. Well, sort of. Sometimes, when I press ctrl+enter it will pass the first test, and then other times, with no changes to the script, it won’t.
Here’s my code :
var out = ‘’;
function repeatStringNumTimes(str, num) {
// repeat after me
if (num<=0) {`
return out+’’;
} else {
out += str;
repeatStringNumTimes(str,num-1);
}
return out;
}
repeatStringNumTimes("*", 8);
I had thought that maybe it’s because I was using a global variable but that still doesn’t explain why sometimes it works for one of the tests and other times it doesn’t.
Anyone able to shed any light on this for me?
Thanks!
Bob