Forked from anonymous/bonfire-repeat-a-string-repeat-a-string?solution=function%20repeat(str%2C%20num)%20%7B%0A%20%20%2F%2F%20repeat%20after%20me%0A%20%20var%20newString%20%3D%20%22%22%3B%0A%20%20while%20(num%20%3E%200)%20%7B%0A%20%20%20%20newString%20%2B%3D%20str%3B%0A%2
Last active
November 26, 2015 01:58
-
-
Save twhite96/a9327138e1af8ff4d8a7 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/twhite96 's solution for Bonfire: Repeat a string repeat a string
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: @twhite96 | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-repeat-a-string-repeat-a-string?solution=function%20repeat(str%2C%20num)%20%7B%0A%20%20%2F%2F%20repeat%20after%20me%0A%20%20var%20newString%20%3D%20%22%22%3B%0A%20%20while%20(num%20%3E%200)%20%7B%0A%20%20%20%20newString%20%2B%3D%20str%3B%0A%20%20%20%20num--%3B%0A%20%20%7D%0A%20%20return%20newString%3B%0A%7D%0A%0Arepeat(%22abc%22%2C%203)%3B%0A | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function repeat(str, num) { | |
// repeat after me | |
var newString = ""; | |
while (num > 0) { | |
newString += str; | |
num--; | |
} | |
return newString; | |
} | |
repeat("abc", 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment