Created
March 9, 2016 15:21
-
-
Save avermeulen/e5efbac6e92623920102 to your computer and use it in GitHub Desktop.
This file contains 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> | |
<meta charset="utf-8"> | |
<title></title> | |
</head> | |
<body> | |
<div class="number"></div> | |
<div class="number"></div> | |
<div class="number"></div> | |
</body> | |
<script type="text/javascript"> | |
var random = function(max){ | |
return Math.floor(Math.random() * max) + 1; | |
}; | |
//get all the number div's | |
var numbers = document.querySelectorAll(".number"); | |
//loop through all the div's and allocate a random number | |
for (var i = 0; i < numbers.length; i++) { | |
var number = numbers[i]; | |
number.innerHTML = random(2); | |
} | |
//checking for matched | |
if (numbers[0].innerHTML === numbers[1].innerHTML){ | |
alert("match!"); | |
} | |
if (numbers[1].innerHTML === numbers[2].innerHTML){ | |
alert("bottom match!"); | |
} | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment