Basic Algorithm Scripting - Repeat a String Repeat a String

Hey! So im working on this problem but not sure what’s wrong. The console.log statement is actually giving what I am expecting. I know it is an array but I am converting to a string with .join() method. Can some one point me to the right direction or explain why it is Im failing?

Your code so far

function repeatStringNumTimes(str, num) {
  let answer = []
for(let i = 0; i < num; i++){
answer.push(str)

}
let result = answer.join("")
console.log(result)
  return str;
}

repeatStringNumTimes("abc", 3);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36

Challenge: Basic Algorithm Scripting - Repeat a String Repeat a String

Link to the challenge:

What are you returning?

OMG I cant believe it I think im just burnt LOL

No worries, it happens! For the problems that ask you to return a value, you could debug like this:

function repeatStringNumTimes(str, num) {
  // your solution
}

// send the return value of your function call to console.log
console.log(repeatStringNumTimes("abc", 3));
1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.