Home > Back-end >  how do I repeat an image in java script using a for loop so that the picture is printed multiple tim
how do I repeat an image in java script using a for loop so that the picture is printed multiple tim

Time:01-31

so I have a little sailboat with a drawing of the moon and the sun. How would I create a for loop so that the sailboat, moon and the sun all are repeated across the x and y axis's without repeating the same instructions over and over. The code I made doesn't run when I save it and open the file.

for(var x = 0; x <= 600; x 200) 
                {
                    for(var y = 0; y <= 600; y 200)
                    {
                            drawWholeBoat(ctx, 200, 300); 
                    }
                }

CodePudding user response:

Replace with this code, check comments for details:

for (let x = 0; x <= 600; x  = 200) {
    for (let y = 0; y <= 600; y  = 200) {
      drawWholeBoat(ctx, x, y);
    }
}
  •  Tags:  
  • Related