Buen día a todos!.
Este es mi aporte para el ejercicio de adivinar un número con ''n'' número de intentos.
<meta charset="UTF-8">
<h1>PROGRAM THAT ASKS FOR ITERACTIONS NUMBER AND GUESS A NUMBER</h1>
<script>
function saltarLinea() {
document.write("<br>");
document.write("<br>");
document.write("<br>" + "<hr>");
document.write("<br>");
document.write("<br>");
}
function imprimir(frase) {
document.write("<big>" + frase + "</big>");
saltarLinea();
}
function guessNumber(iteractions, number){
while(iteractionCounter<=iteractionTimes){
inmindNumber = parseInt(prompt("Guess (enter) a number! "));
if (correctNumber == inmindNumber){
imprimir ("You win!" + "The correct number is: " + correctNumber);
break;
}
else{
iteractionCounter++;
if (iteractionCounter>iteractionTimes){
imprimir ("You lost! :( The correct number was: " + correctNumber);
}
}
}
}
var correctNumber = Math.round(Math.random()*10);
var iteractionCounter = 1;
var iteractionTimes = parseInt(prompt("How many iteractions you want?"));
var inmindNumber = 0;
guessNumber(iteractionTimes, inmindNumber);
</script>
Un saludo!.