Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
25
rated 0 times [  29] [ 4]  / answers: 1 / hits: 15507  / 6 Years ago, fri, october 19, 2018, 12:00:00

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!


More From » javascript

 Answers
23

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));




[#53292] Monday, October 15, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
lucianom

Total Points: 601
Total Questions: 98
Total Answers: 109

Location: Kenya
Member since Fri, Dec 23, 2022
1 Year ago
lucianom questions
Tue, Feb 22, 22, 00:00, 2 Years ago
Wed, May 5, 21, 00:00, 3 Years ago
Sun, Jan 24, 21, 00:00, 3 Years ago
Sat, Aug 15, 20, 00:00, 4 Years ago
Mon, Jun 22, 20, 00:00, 4 Years ago
;