Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Sorteio Número Randomico/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html lang="pt-BR">

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Exer11 - Aula 6</title>
</head>

<body>

<form>

Chute:<input type="text" id="txtchute"><br>
<input type="button" value="Verificar" id="botao"><br>
Dica: <input type="text" id="txtdica" readonly><br>

</form>

<div id="msg"></div>

<script src="./script/script.js"></script>
</body>

</html>
32 changes: 32 additions & 0 deletions Sorteio Número Randomico/script/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
window.onload = function () {

var num_secreto;
var tentativas = 0;
var div_msg = document.getElementById("msg");
var campo_dica = document.getElementById("txtdica");

num_secreto = sortearNumero();

document.getElementById("botao").onclick = function(){

tentativas++;
var num_chute = parseInt(document.getElementById("txtchute").value);

if (num_chute < num_secreto) {
campo_dica.value = "O número sorteado é maior.";
}

else if (num_chute > num_secreto) {
campo_dica.value = "O número sorteado é menor.";
}

else {
div_msg.innerHTML = "<h1>Parabéns. Você acertou em " +
tentativas + " tentativas</h1>" + "<h3>Pressione F5 para jogar novamente</h3>";
}
}
}

function sortearNumero(){
return Math.round(Math.random() * 100);
}