Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiply a string in JS [duplicate]

Tags:

javascript

i want to display a string as many times I have a generated variable. Therefore I'd like to do something like that, which doesn't work

var shower_total = 7; // this gets generated, but for simplification... 
var uhrzeit = "<p class='clock_item'>Foo</p>";
document.getElementById("uhrzeit_block").innerHTML =5*uhrzeit;

That's why I tried looping it but that doesn't work neither

document.getElementById("uhrzeit_block").innerHTML = 
 for(b=0, b <= shower_total; b++){
   uhrzeit
};

What do I do wrong or what would be a possible - beginner-compatible - solution. Thanks!

like image 206
Daiaiai Avatar asked Jul 11 '26 17:07

Daiaiai


1 Answers

You could use String#repeat instead of a multiplication of a string. This does not work for value who can not converted to a number.

var uhrzeit = "<p class='clock_item'>Foo</p>";

console.log(uhrzeit.repeat(5));
like image 181
Nina Scholz Avatar answered Jul 13 '26 08:07

Nina Scholz