From 8ec38c4b573fe89ccf343f70a7003a1f5d61866b Mon Sep 17 00:00:00 2001 From: Isah Jacob Date: Sat, 29 Oct 2022 11:05:02 +0100 Subject: [PATCH] created a variable that hold the string. loop through the number of times the string is repeated. assigned the number time the string is repeated to the variable created --- 02_repeatString/repeatString.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/02_repeatString/repeatString.js b/02_repeatString/repeatString.js index 4359bbe..721233d 100644 --- a/02_repeatString/repeatString.js +++ b/02_repeatString/repeatString.js @@ -1,6 +1,16 @@ -const repeatString = function() { - +const repeatString = function(string, num) { + var repeatedWord = ""; + while (num > 0){ + repeatedWord += string; + num--; + } + return repeatedWord; }; +repeatString('hey', 3); +repeatString('hey', 10); +repeatString('hey', 1); +repeatString('hey', 0); +repeatString('hey', -1) // Do not edit below this line module.exports = repeatString;