I'm learning how to use while loops, and although I more or less have the concept down I'm having some trouble getting a while loop to write text repeatedly to an html element.
var text = prompt("What would you like logged to screen?");
//I may need to convert prompt output to a number
var repeatText = prompt("How many times would you like to print the text?");
var loopCount = 0;
while (loopCount < repeatText) {
//I want text to print out on screen "x" times, where x is equal to the numerical value of loopCount
document.getElementById("outputHolder2").innerHTML += text;
loopcount++;
}
//this isn't outputting to outputHolder1 after loop
document.getElementById("outputHolder1").innerHTML = loopCount;
#outputHolder1 {
margin: 0px;
padding: 10%;
background-color: lightBlue;
text-align: center;
font-size: 20px;
font-weight: 5;
}
#outputHolder2 {
padding: 2% 10% 0% 10%;
}
<div>
<p id="outputHolder1">
NUMBER OF TIMES TO LOOP:
</p>
<p id="outputHolder2">
</p>
</div>
From what I understand, .innerHTML += text should copy the inner text of an HTML element, and add new text to it, however I haven't been able to make this work in a loop.
Raw Javascript solutions only please.