DEV Community

Calvin
Calvin

Posted on • Edited on

Repeated String Example in JavaScript



var string;
var repeat;


var stringRepeater = function (string, repeat) {

 var repeatedString = "";

  while (repeat > 0){

    repeatedString+=string;
    repeat--

  }

  return repeatedString

}


Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
jonrandy profile image
Jon Randy 🎖️
const stringRepeater = (string, repeat) => string.repeat(repeat)
Enter fullscreen mode Exit fullscreen mode