const message:string = "Baby";
//Using While Loop
function repeatStringWithWhile(str,times){
let myString = "";
while(times>0){
myString +=str;
times--;
}
return myString;
}
//Recursion
function repeatStringWithRecursion(str,times){
if(times<0){
return "";
}
if(times == 1){
return str;
}
return str + repeatStringWithRecursion(str,times-1);
}
//Predefined function
function repeatStringWithReverse(str,times){
return times<0?"":str.repeat(times);
}
console.log("With While Loop : "+ repeatStringWithWhile(message,3));
console.log("With Recursion : "+ repeatStringWithRecursion(message,4));
console.log("With PreDefined Function : "+ repeatStringWithReverse(message,-2));
To embed this project on your website, copy the following code and paste it into your website's HTML: