Write a Raptor program that will generate a random number between 1 and 10; do not display the randomly generated number. Let the user guess within 3 tries what the random number is. Display hints to help the user, for example "Your guess was too high!". Display appropriate messages based on each try, for example, "1 remaining try" or "You guessed correctly!"

Respuesta :

Answer:

Using javascript, explanation with javascript comment

Explanation:

function guessNumber(){

var randomize= math.random()*10;

var roundrand= math.floor(randomize);

var getInput= prompt("guess number from 1 to 10");

var x= 3;

do(

if(getInput>roundrand){

Console.log("your guess is too high");

guessNumber();

}

if(getInput<roundrand){

Console.log("your guess is too high");

guessNumber();

}

else{

Console.log("you are correct pal!");

break;

}

)

while(x<=3)

}

/*Observe that we have used a recursive function that calls the function guessNumber again inside the function definition if the input fails the if condition and doesn't guess correctly. It checks for a correct number 3 times with the do... while loop and breaks out of the function once the user enters a correct input.*/