+ 1
Javascript loop help.
c.anything(20,20,50,50); c.anything(30,20,50,50); c.anything(40,20,50,50); c.anything(50,20,50,50); I want to type this code only once. and want to change the first value for a certain times like 20 times. I need to create a loop now .but couldn't figure it out. #javascript help
7 ответов
+ 4
I'm not sure if I understand what you want to do. Your code actually creates 300 elements. They're just overlapping.
Check this code. I'm not sure if this is what you want to do
https://code.sololearn.com/W0AeTdS4UZ85/?ref=app
+ 2
You can do:
for(var x=20; x<60; x+=10){
c.anything(x,20,50,50);
}
+ 2
thanks Jonathan Pizarra
+ 1
for(var i = 0;i<300;i+=50){
var canvas = document.querySelector("canvas");
canvas.width = window.innerWidth;
canvas.height=window.innerHeight;
var c = canvas.getContext("2d");
c.fillStyle="#333";
c.fillRect(i,20,30,30);
}
it should creat a line but its just creating 1 element
+ 1
https://code.sololearn.com/WmOj78vUoLxR/?ref=app
check this I want it to start from width 50 and end at 250 and it should be continued
+ 1
I finally did what I wanted to do. It was not that tough but I didn't knew that could be done by this.
https://code.sololearn.com/WWkIr57N92G2/#html
0
Thanks again for helping me and if you have any recommendation to look it good suggest me please.