I've watched Udemy video. The instructor created a basic car race with jQuery. When the race is over, it shows the result of race and writes which car is the first and second. However, I don't understand how the function knows which car came in first? How does the function know which place is first and second? Can someone say how does "Complate" work?
$("#race").click(function() {
// This function I don't understand
function Check() {
if (Complate == false) {
Complate = true;
} else {
place = "second";
}
}
// Find Car width
var CarWidth1 = $("#car1").width();
var CarWidth2 = $("#car2").width();
// Find stop places
var WayWidth = $(window).width() - CarWidth1;
var bottomWidth = $(window).width() - CarWidth2;
// Find speed
var carTime1 = Math.floor((Math.random() * 5000) + 1);
var carTime2 = Math.floor((Math.random() * 5000) + 1);
//Place
var place = "first";
// This one
var Complate = false;
$("#car1").animate({
left: WayWidth
}, carTime1, function() {
Check();
$("#span1").text("Finished in " + place + " place and clocked in at " +
carTime1 + " milliseconds")
});
$("#car2").animate({
left: bottomWidth
}, carTime2, function() {
Check();
$("#span2").text("Finished in " + place + " place and clocked in at " +
carTime2 + " milliseconds")
});
});