Created
December 10, 2015 03:58
-
-
Save joePichardo/50441aa95305c15091fc 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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Bonfire: Repeat a string repeat a string | |
// Author: @joepichardo | |
// 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 | |
//creates an empty string to return | |
//if num is less than 0 | |
//if num isn't string is add "num" times | |
//then returned | |
var addToString = ""; | |
if(num > 0){ | |
for(var i = 0; i < num; i++){ | |
addToString += str; | |
} | |
return addToString; | |
} | |
return addToString; | |
} | |
repeat("abc", 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment