Created
January 7, 2018 20:17
-
-
Save pedrotoliveira/9a892b323dcb4359623d8aa5a6e80c86 to your computer and use it in GitHub Desktop.
brincadeira da mega
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 class="no-js" lang=""> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="x-ua-compatible" content="ie=edge"> | |
<title>Números da Megasena</title> | |
<meta name="description" content=""> | |
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | |
<link rel="apple-touch-icon" href="icon.png"> | |
<!-- Place favicon.ico in the root directory --> | |
<!-- Bootstrap CSS --> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous"> | |
</head> | |
<body> | |
<!--[if lte IE 9]> | |
<p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="https://browsehappy.com/">upgrade your browser</a> to improve your experience and security.</p> | |
<![endif]--> | |
<div class="container"> | |
<h1>Megasena</h1> | |
<div id="message" class="alert alert-success" role="alert"> | |
<strong>Well done!</strong> Você selecionou 15 elementos! | |
</div> | |
<!-- Add your site or application content here --> | |
<form> | |
<div class="form-group row"> | |
<label for="selectNumber" class="col-sm-2 col-form-label">Adicione Números:</label> | |
<select id="selectNumber" name="selectNumber" class="col-sm-2 form-control" onchange="controller.addNumber()"> | |
<option selected="true">Selecione</option> | |
</select> | |
</div> | |
<div class="form-group row"> | |
<label for="numbers" class="col-sm-3 col-form-label">Numeros Escolhidos</label> | |
<textarea id="numbers" name="numbers" rows="1" class="form-control disabled" disabled="true"></textarea> | |
</div> | |
<div class="form-group row"> | |
<button id="calculateButton" type="button" class="col-sm-3 form-control btn btn-primary" onclick="controller.calculate()" disabled="true">Calcular</button> | |
</div> | |
<div class="form-group row"> | |
<ul id="results" class="list-group"> | |
</ul> | |
</div> | |
</form> | |
<!-- jQuery first, then Tether, then Bootstrap JS. --> | |
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script> | |
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script> | |
</div> | |
<script type="text/javascript"> | |
var controller = { | |
numbers : [], | |
positions : [], | |
results : [], | |
addNumber : function() { | |
var val = jQuery("#selectNumber").val(); | |
if (val === "Selecione") { | |
return; | |
} | |
if (this.numbers.length === 0) { | |
this.numbers.push(val); | |
jQuery("#numbers").text(this.numbers); | |
} | |
if (!this.numbers.includes(val) && this.numbers.length < 15) { | |
this.numbers.push(val); | |
jQuery("#numbers").text(this.numbers); | |
} | |
if (this.numbers.length === 15) { | |
jQuery("#message").show(); | |
} | |
if (this.numbers.length > 5) { | |
jQuery("#calculateButton").prop("disabled", false); | |
} | |
}, | |
calculate : function() { | |
this.positions = []; | |
this.results = []; | |
jQuery(".list-group-item").remove(); | |
if (this.numbers.length < 7) { | |
for (var x = 0; x < 6; x++) { | |
this.positions.push(this.numbers[x]); | |
} | |
this.results.push(this.positions); | |
var listItem = "<li class=\"list-group-item\">" + this.results + "</li>"; | |
jQuery("#results").append(listItem); | |
} | |
if (this.numbers.length > 6) { | |
for (var pos = 0; pos < this.numbers.length; pos++) { | |
for (var x = 0; x < 6; x++) { | |
if ((x + pos) < this.numbers.length) { | |
this.positions.push(this.numbers[x + pos]); | |
} | |
if ((x + pos) >= this.numbers.length) { | |
var elemPos = (x + pos) - this.numbers.length; | |
this.positions.push(this.numbers[elemPos]); | |
} | |
} | |
this.results.push(this.positions); | |
var listItem = "<li class=\"list-group-item\">" + this.results + "</li>"; | |
jQuery("#results").append(listItem); | |
this.positions = []; | |
this.results = []; | |
} | |
} | |
} | |
}; | |
$(document).ready(function() { | |
jQuery("#message").hide(); | |
for (var n = 0; n < 60; n++) { | |
var nOption = "<option>" + (n + 1) + "</option>"; | |
jQuery("#selectNumber").append(nOption); | |
} | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment