Skip to content

Instantly share code, notes, and snippets.

@avermeulen
Created March 9, 2016 15:21
Show Gist options
  • Save avermeulen/e5efbac6e92623920102 to your computer and use it in GitHub Desktop.
Save avermeulen/e5efbac6e92623920102 to your computer and use it in GitHub Desktop.
<!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