Ok, so on the Repeat a String, my code as follows won’t work:
function repeatStringNumTimes(str, num) { let newStr = " "; for (var i=0; i < num; i++) { newStr += str; } return newStr; }
When I use the javascript test window, it works fine, but when I run the tests through the fcc window, it fails on many.
Any ideas why?
it is because your starting value is a space. so if you have repeatStringNumTimes("moo", 3), the string returned is actually " moomoomoo" instead of "moomoomoo" and " moomoomoo" === "moomoomoo" is false, so the tests fail
repeatStringNumTimes("moo", 3)
" moomoomoo"
"moomoomoo"
" moomoomoo" === "moomoomoo"
Oh my! Thank you! I seem to do that a lot. I always set an empty string to a space, and that’s not empty.
You can use JS function repeat.