<!DOCTYPE html>
<html lang="en">
<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>Secret Game V3</title>
</head>
<body>
<input/>
<button>verificar si acertó con el secreto</button>
<script>
function aleatorio(){
return Math.round(Math.random()*10);
}
function raffle(cant){
var secrets = [];
var cont = 1;
while(cont<=cant){
var numRand = aleatorio();
var found = false;
if(numRand!=0){
for(var i = 0 ; i<secrets.length; i++){
if(numRand == secrets[i]){
found = true;
break;
}
}
if(found == false){
secrets.push(numRand);
cont++;
}
}
}
return secrets;
}
var secrets = raffle(4);
console.log(secrets);
var input = document.querySelector("input");
input.focus();
function verificar() {
found = false;
for (var i = 0; i < secrets.length; i++) {
if (parseInt(input.value) == secrets[i]) {
alert("usted acertó");
found = true;
break;
}
}
if (found == false) {
alert("usted erro");
}
input.value = "";
input.focus();
}
var button = document.querySelector("button");
button.onclick = verificar;
</script>
</body>
</html>