Welcome to Westonci.ca, your one-stop destination for finding answers to all your questions. Join our expert community now! Join our Q&A platform and get accurate answers to all your questions from professionals across multiple disciplines. Get quick and reliable solutions to your questions from a community of experienced experts on our platform.

8.10.8 guess the passcode codehs

Sagot :

Answer:

sorry its late

Explanation:

/*

* Write a program that guesses every possible 4 digit passcode

* combinations until the correct passcode is guessed.

*

* The passcode is randomly generated and stored in the variable

* secretPasscode.

*

* Print out how many guesses it took to guess the correct passcode.

*/

function start() {

   var correctCode = generateRandomPasscode();

   var b = 0;

   while(true){

       var guessCode = generateRandomPasscode();

       b++;

       if(isCorrect(guessCode, correctCode)){

           println("The correct passcode was " + guessCode);

           println("It took you " + b + " tries to guess it");

       break;

       }

   }

}

function isCorrect(guessCode, correctCode) {

   return guessCode == correctCode;

}

function generateRandomPasscode() {

   var randomPasscode = "";

   for(var i = 0; i < 4; i++) {

       var randomDigit = Randomizer.nextInt(0, 9);

       randomPasscode += randomDigit;

   }

return randomPasscode;

}

We hope our answers were helpful. Return anytime for more information and answers to any other questions you may have. Thanks for stopping by. We strive to provide the best answers for all your questions. See you again soon. We're glad you visited Westonci.ca. Return anytime for updated answers from our knowledgeable team.