xxxxxxxxxx
let text = 'Hello world!';
let result = text.repeat(4);
console.log(result);
xxxxxxxxxx
setInterval(function(){
console.log("Hello");
console.log("World");
}, 2000); //repeat every 2s
xxxxxxxxxx
const chorus = 'Because I\'m happy. ';
console.log(`Chorus lyrics for "Happy": ${chorus.repeat(27)}`);
// expected output: "Chorus lyrics for "Happy": Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. "
xxxxxxxxxx
/* The string.repeat(n) method constructs and returns a new string
with "n" number of copies. */
const chorus = "Because I'm happy. ";
console.log(`Chorus lyrics: ${chorus.repeat(3)}`);
// → "Chorus lyrics: Because I'm happy. Because I'm happy. Because I'm happy. "
// Use within a function
greeting = (n, words) => words.repeat(n);
console.log(greeting(5, "howdy "));
// → "howdy howdy howdy howdy howdy "
xxxxxxxxxx
function repeatStr (n, s) {
return s.repeat(n)
}
/////////////////////////////similar///////////////////////////////////////////
repeatStr = (n, s) => s.repeat(n);
xxxxxxxxxx
let text = 'Hello Aliens!';
let result = text.repeat(2);
console.log(result); //Hello Aliens!Hello Aliens!