My solution to this after searching through the mozilla documentation, was to use the string repeat method. The exercise text doesn’t say we can’t use this, but it seems too easy…? I can imagine doing it other ways with a loop, though is it necessary?
function repeatStringNumTimes(str, num) {
// repeat after me
if (num > 0) {
return str.repeat(num);
}
else return "";
}
repeatStringNumTimes("abc", 3);