<meta charset="utf-8">
<input/>
<button>Descubra o numero segredo</button>
<script>
function sorteia(){
return Math.round (Math.random()*10)
}
function sorteiaNumeros(quantidade){
var segredos=[];
var numero = 1
while (numero<=quantidade){
numeroAleatorio = sorteia ()
var achou = false
for (var j=0 ; j < segredos.lenght ; j++){
if (segredos[j] == numeroAleatorio){
achou =true
break
}
}
if (achou==false){
segredos.push (numeroAleatorio)
numero++
}
}
return segredos ;
}
var segredos = sorteiaNumeros(9)
console.log (segredos)
var input = document.querySelector ("input");
input.focus()
function verificaSegredo () {
var achou = false
for (var i=0 ; i < segredos.length ; i++ ){
if (input.value == segredos[i]) {
alert ("você ACERTOU !!!! O segredo eram "+ segredos)
achou = true;
break
}
}
if (achou == false) {
alert ("você ERROU !!!! O segredo eram "+ segredos);
}
input.value = ""
input.focus()
}
var button = document.querySelector ("button");
button.onclick = verificaSegredo ;
</script>