Skip to content

Instantly share code, notes, and snippets.

  • Save rjmccallumbigl/30df14ace459e88cba0a to your computer and use it in GitHub Desktop.
Save rjmccallumbigl/30df14ace459e88cba0a to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/rjmccallumbigl 's solution for Bonfire: Repeat a string repeat a string
// Bonfire: Repeat a string repeat a string
// Author: @rjmccallumbigl
// 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%20%0A%20%20var%20i%20%3D%200%3B%0A%20%20var%20sentence%20%3D%20%22%22%3B%0A%20%20%0A%20%20while%20(i%20%3C%20num)%7B%0A%20%20%20%20%0A%20%20%20%20sentence%20%3D%20sentence.concat(str)%3B%0A%20%20%20%20i%2B%2B%3B%0A%20%20%20%20%0A%20%20%7D%0A%20%20%0A%20%20return%20sentence%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 i = 0;
var sentence = "";
while (i < num){
sentence = sentence.concat(str);
i++;
}
return sentence;
}
repeat("abc", 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment