Created
August 24, 2015 17:55
-
-
Save mayfer/b410fdf35ba554ec63f5 to your computer and use it in GitHub Desktop.
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
/* | |
// local | |
var separator = "| |"; | |
// global | |
separator = "| |"; | |
// string concat | |
message = "one" + separator + "two"; | |
// puts | |
console.log(message); | |
*/ | |
// console.log(multiply(5, 6)); | |
// declare before everything else | |
// function multiply(a, b) { | |
// declare at a specific time | |
var multiply = function(a, b) { | |
if(a == undefined || b == undefined) { | |
console.log("At least two arguments needed"); | |
} else { | |
console.log(a, b); | |
return a * b; | |
} | |
} | |
// each(array, function(element) { // do something }); | |
var each = function(array, operator) { | |
for(var i=0; i<array.length; i++) { | |
operator(array[i]); | |
} | |
} | |
each([345, 213, 687, 33, 1], function(elem) { | |
var multiplier = 10; | |
var times_ten = function(e) { | |
return e * multiplier; | |
} | |
console.log(times_ten(elem)); | |
}); | |
var count = 0; | |
while(count < 10) { | |
setTimeout(function() { | |
console.log("hello world once again"); | |
}, 500 * count); | |
count += 1; | |
} | |
var task = function(delay) { | |
setTimeout(function() { | |
console.log("half a second!"); | |
task(delay); | |
}, delay); | |
} | |
task(500); | |
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
<html> | |
<head> | |
<title>intro to JS</title> | |
<style> | |
body { margin: 0; padding: 50px; font-family: monospace; } | |
.dot { width: 30px; height: 30px; margin: -15px; background: #000; border-radius: 50%; position: absolute; } | |
</style> | |
</head> | |
<body> | |
<h1 id="title">weeeee</h1> | |
<script> | |
var randomColor = function() { | |
return '#'+Math.floor(Math.random()*16777215).toString(16); | |
} | |
document.addEventListener("mousemove", function(e) { | |
var dot = document.createElement("div"); | |
dot.className = "dot"; | |
dot.style.top = e.pageY + "px"; | |
dot.style.left = e.pageX + "px"; | |
dot.style.backgroundColor = randomColor(); | |
document.body.appendChild(dot); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment