I have 4 div with ids: HTML:
<div id="car1">Car 1</div>
<div id="car2">Car 2</div>
<div id="car3">Car 3</div>
<div id="car4">Car 4</div>
<div class="leftCar"></div>
<div class="rightCar"></div>
<button id="button">Race</button>
Now I pick 2 out of 4 to "race" JS:
// choose a car to compare
$("#car1").on("click", function() {
$("#car1").appendTo(".leftCar");
});
// choose the other car to compare
$("#car2").on("click", function() {
$("#car2").appendTo(".rightCar");
});
How can I create objects/var and connect the values to the existing ids to compare them? Something like this?
var car1 = {"topSpeed":"100","fuel":"50"};
var car2 = {"topSpeed":"80","fuel":"90"};
How to make the cars' top speed increase (+10) every time I hit button Race and their fuel decrease (-10)? Also, how to remove/hide the car with fuel = 0?