scrimba
Learn JavaScript loops and iteration
while and do...while loops: challenge
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

while and do...while loops: challenge
AboutCommentsNotes
while and do...while loops: challenge
Expand for more info
index.js
run
preview
console
/* Challenge: Using while and do...while loops
*
* You need to spray the plots to remove the bugs
* Create a variable to hold the number of bugs
* Write a function named protectPlants:
* Takes a parameter "thisPlot"
* Uses a while loop
* * for each plot while there are still bugs remaining
* * call the spray function
* !REMEMBER to stop at the final plot
*
* Call your protectPlants function with a starting plot value
*/

const plots = document.querySelectorAll(".plot")


function spray(thisPlot){
plots[thisPlot].classList.add("sprayed")
plots[thisPlot].innerHTML = ""
}
Console
/index.html
-4:10