Debugging Repeat a String Repeat a String

Tell us what’s happening:
I can run the following code in my browser console, and I am getting the correct answers for all the test cases. However, I am not passing most test cases when I run this code in the freecodecamp editor.

Can someone help me understand why?

Your code so far


function repeatStringNumTimes(str,num){
    if (num<0){
      return "";
    }
    else {
      var p = str;
      let i =0;
      while (i <num){
        p+=str;
        i++
      }
      console.log(p);
    return p;

    }
    
}

repeatStringNumTimes("abc", 3);

Your browser information:

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

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/repeat-a-string-repeat-a-string

Hello Will,

As you mentioned you could see the results in browser console, so you can confirm if the results are right or false.
Please note repeatStringNumTimes("abc", 3); should return abcabcabc, but your code returns one more step(4 instead of 3)

hint: check your var p = str, it’s one step itself.

Keep going on great work.

var p = ""; 

Thanks!!!