An alternative solution, and I believe it to be simpler, would be to create an array and fill in the same with the desired value, and return a Join similarly so that it is not necessary to concatenate values to string, for example:
function repete(palavra, qtd){
// Cria um array com length determinado por "qtd"
const array = new Array(qtd).fill(palavra);
// Troque o - por espaço ou outro valor para determinar como as palavras devem ser separadas
return array.join(' - ');
}
document.write(repete('Palavra 1', 5) + "<br />");
document.writeln(repete('Palavra 2', 2) + "<br />");
document.writeln(repete('Palavra 3', 10) + "<br />");
Concatenating Strings into a for is not a problem as long as the number of repetitions is small and the text is not too large, but you may encounter problems if the number of repetitions or the text is too large.
Both mine and the other answers given so far solve the problem described in the statement, if anything is missing then you should edit your question and add details about what you really need otherwise your question will be closed.
Avoid editing your questions by adding other questions on your own as this invalidates the answers given previously, since you are new here, take some time to read more about the Stackoverflow Survival Guide
Edit your question by trying to better describe what you really need, as there are 4 answers that meet your request and none of them meet your need
– Evilmaax