-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparImpar.html
54 lines (46 loc) · 1.4 KB
/
parImpar.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Logica de Programação Javascript</title>
<style>
body {
font-family: sans-serif;
}
</style>
</head>
<body>
<h1>Jogo do par ou impar</h1>
<p>Digite um número de 0 a 5</p>
<input type="number" id="meuNumero" min="0" max="5">
<button onclick="jogar()">Jogar</button>
<script>
var nComputador = '',
nJogador = '',
minhaEscolha = 'par';
function sortear(max) {
return Math.floor(Math.random() * max);
}
function jogar() {
nJogador = document.querySelector('#meuNumero').value;
nComputador = sortear(5);
if (!nJogador) {
alert('Primeiro digite um número')
}
nJogador = parseInt(nJogador);
var total = nJogador + nComputador;
var resultado = (total % 2 === 0) ? 'pa' : 'impar';
verificarResultado(resultado);
}
function verificarResultado(resultado) {
if (minhaEscolha == resultado) {
alert('Eu ganhei')
} else {
alert('O computador ganhou');
}
console.log('nComputador', nComputador);
console.log('nJogador', nJogador);
}
</script>
</body></html>