Can someone explain why this works only for the positive numbers? I fail the test when it gets to num=-2, but I thought adding the “if” function would take care of that. Thanks!
function repeatStringNumTimes(str, num) {
var anythingString = String(str);
var answer = anythingString.repeat(num);
if (num >0) {return answer;} else return “”;
}
You need to check for the negative number at the start of the function and return the blank string then. The rest of your code is fine. Of course you will just need to return answer at the end without the if/else statement.
FYI - There is no need to use String(str), because the challenge says the first argument will be a string.