Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how do I repeat an image in java script using a for loop so that the picture is printed multiple times in the browser

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); 
                    }
                }

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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);
    }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading