Skip to content

Instantly share code, notes, and snippets.

@natekandler
Created May 15, 2014 14:13
Show Gist options
  • Save natekandler/370f3d5655cc43c36190 to your computer and use it in GitHub Desktop.
Save natekandler/370f3d5655cc43c36190 to your computer and use it in GitHub Desktop.
JS racer
var counter1 = 0
var counter2 = 0
$(document).ready(function(){
var $player1 = $("#player1_strip");
var $player2 = $("#player2_strip");
$(document).keyup(function(event){
// event.which for keyup will return the ascii value for the key that was pressed
if (event.which === 80){
$($player1.children()[ counter1 ]).html("")
counter1++
$($player1.children()[ counter1 ]).html("car")
}
else if (event.which === 81){
$($player2.children()[ counter2 ]).html("")
counter2++
$($player2.children()[ counter2 ]).html("car")
}
});
}) ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment