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
This commit is contained in:
parent
342604b4e2
commit
8ec38c4b57
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue