From db251496792e9222de5882f75e069a6e9488ac56 Mon Sep 17 00:00:00 2001 From: DEV RYAN <85769101+offryan@users.noreply.github.com> Date: Tue, 20 Feb 2024 11:13:46 -0300 Subject: [PATCH] =?UTF-8?q?Sorteio=20N=C3=BAmero=20Randomico?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sorteio Número Randomico --- "Sorteio N\303\272mero Randomico/index.html" | 26 +++++++++++++++ .../script/script.js" | 32 +++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 "Sorteio N\303\272mero Randomico/index.html" create mode 100644 "Sorteio N\303\272mero Randomico/script/script.js" diff --git "a/Sorteio N\303\272mero Randomico/index.html" "b/Sorteio N\303\272mero Randomico/index.html" new file mode 100644 index 0000000..76f913e --- /dev/null +++ "b/Sorteio N\303\272mero Randomico/index.html" @@ -0,0 +1,26 @@ + + + + + + + + Exer11 - Aula 6 + + + + +
+ + Chute:
+
+ Dica:
+ +
+ +
+ + + + + \ No newline at end of file diff --git "a/Sorteio N\303\272mero Randomico/script/script.js" "b/Sorteio N\303\272mero Randomico/script/script.js" new file mode 100644 index 0000000..728fc68 --- /dev/null +++ "b/Sorteio N\303\272mero Randomico/script/script.js" @@ -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 = "

Parabéns. Você acertou em " + + tentativas + " tentativas

" + "

Pressione F5 para jogar novamente

"; + } + } +} + +function sortearNumero(){ + return Math.round(Math.random() * 100); +} \ No newline at end of file