Created
May 11, 2017 00:24
-
-
Save dursk/49be74e44eac4e7722c2e53787d293f6 to your computer and use it in GitHub Desktop.
Exported from Popcode. Click to import: https://popcode.org/?gist=49be74e44eac4e7722c2e53787d293f6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Page Title</title> | |
</head> | |
<body> | |
<div id="game"> | |
<div id="bar"></div> | |
</div> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"enabledLibraries":["jquery"],"hiddenUIComponents":["editor.html"]} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$("body").keydown(function(event) { | |
var position = $("#bar").offset().left; | |
if (event.which === 37 && position > 13) { | |
$("#bar").css("left", position - 10); | |
} else if (event.which === 39 && position < 483) { | |
$("#bar").css("left", position + 10); | |
} else { | |
return; | |
} | |
}); | |
// STEP 1 | |
// Set the currentBlockIds variables to an empty array. | |
var currentBlockIds; | |
function generateRandomId() { | |
// STEP 2: set randomNumber to a random integer | |
// between 0 and 10,000 | |
var randomNumber; | |
return "A" + randomNumber; | |
} | |
function generateRandomOffset() { | |
// STEP 3: return a random integer between 0 and 480 | |
return; | |
} | |
function createBlock() { | |
// STEP 4 | |
// Call the generateRandomId function to set the id variable. | |
var randomId; | |
// STEP 5 | |
// Call the generateRandomOffset function to set the randomOffset | |
// variable. | |
var randomOffset; | |
$("#game").append("<div id=" + randomId + " class=block style=left:" + randomOffset + "px></div>"); | |
currentBlockIds.push(randomId); | |
} | |
// STEP 6 | |
// Uncomment the code below to see what you've done so far! | |
// window.setInterval(createBlock, 1200); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#game { | |
border: 5px solid black; | |
height: 500px; | |
width: 500px; | |
} | |
#bar { | |
background-color: black; | |
height: 8px; | |
width: 30px; | |
position: absolute; | |
margin-top: 480px; | |
} | |
.block { | |
background-color: red; | |
height: 10px; | |
width: 10px; | |
position: absolute; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment