/
main.js
41 lines (29 loc) · 1.13 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// create car object
// start will begin function (function start()?)
// 'up' key will move redCar by 1 unit / 'down' key will move blueCar by 1 unit
// first car to reach unit of 10 wins (finish line)
// text will display (display:none?) when the winner reach finish line
// if(movePosition.keyup) {
// // TODO: Grab the value of the current margin-left
// //TODO: Increment that value in a local variable
// // TODO: set the margin-left value to the updated local variable
var blueCar = document.getElementById('blueCar');
blueCar.go = 0;
var redCar = document.getElementById('redCar');
redCar.go = 0;
var blueWon = document.getElementById('blueWon');
var redWon = document.getElementById('redWon');
document.addEventListener('keyup', function(event) {
if(blueCar.go ===700) { blueWon.style.display = "block" ;return;}
else if
(redCar.go ===700) { redWon.style.display = "block";return;}
else if
(event.keyCode == 38) {
blueCar.go += 50
blueCar.style.marginLeft = blueCar.go + 'px';
}
else if (event.keyCode == 40) {
redCar.go += 50
redCar.style.marginLeft = redCar.go + 'px';
}
})