I created a racing html 5 canvas and JS project that makes use of a colour API. I'm looking to clean up my code. Is there a way I can change the code below into a for loop to save on the amount of code that has to be re-typed? I was thinking of a for loop but can't get my head around the idea of how I would chnage the values for the attributes on each iteration?
c1 = new Car({ x: 0, y: 100, colour: "#" + json.colors[0].hex, windowsColour: "#" + json.colors[1].hex, number: 1 });
c2 = new Car({ x: 0, y: 250, colour: "#" + json.colors[3].hex, windowsColour: "#" + json.colors[2].hex, number: 2, });
c3 = new Car({ x: 0, y: 400, windowsColour: "#" + json.colors[4].hex, colour: "#" + json.colors[5].hex, number: 3, });
c4 = new Car({ x: 0, y: 550, windowsColour: "#" + json.colors[6].hex, color: "#" + json.colors[7].hex, number: 4 });