Repeatify

by meetravi

HTML

<!--
2. Create a “native” method

Define a repeat function on the String object. The function accepts an integer that specifies how many times the string has to be repeated. The function returns the string repeated the number of times specified. For example:

 




-->

console.log('hello'.repeatify(3));

 

Should produce ‘hellohellohello’.

JavaScript

String.prototype.repeatify = function (howManyTimes) {
	var repeatedString = '';
  
  for (var i =0; i < howManyTimes; i++) {
  	repeatedString += this.toString();
  }
  
	return repeatedString;
}



console.log('hello'.repeatify(3));