Skip to content

Instantly share code, notes, and snippets.

@piqueen314
Created December 11, 2015 05:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piqueen314/019cd1e813b19686144e to your computer and use it in GitHub Desktop.
Save piqueen314/019cd1e813b19686144e to your computer and use it in GitHub Desktop.
Repeat a given string (first argument) n times (second argument). Return an empty string if n is a negative number.
// Bonfire: Repeat a string repeat a string
// Author: @piqueen314
// Challenge: http://www.freecodecamp.com/challenges/bonfire-repeat-a-string-repeat-a-string
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function repeat(str, num) {
// repeat after me
var newStr="";
for(var i=0; i<num; i++){
newStr=newStr.concat(str);
}
alert(newStr);
return newStr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment