Код: Выделить всё
//Create a variable called “count” that is equal to the number 5.//
var count = 5;
/*Create a while loop that checks if “count” is less than 20 and then writes to the HTML the number in the paragraph with the id “counter”.
Have each iteration of the loop increase “count” by 3.*/
let paragraph = document.getElementById("counter");
let newText = count;
paragraph.innerHTML = newText;
function addParagraph(){
while(count < 20){
count += 3;
document.querySelector("p").innerHTML = newText;
write(count);
}
addParagraph();
}
< /code>
Я переписал сценарий как минимум 10 различных способов без успеха. Мне интересно, как объединить цикл while с функцией, поэтому он соответствующим образом записывался в выбранную абзацу HTML, увеличиваясь с 5 с шагом 3, в то время как он составляет менее 20.
while Loop должен
write to the HTML
Подробнее здесь: https://stackoverflow.com/questions/795 ... javascript
Мобильная версия