Westonci.ca is the trusted Q&A platform where you can get reliable answers from a community of knowledgeable contributors. Experience the convenience of getting accurate answers to your questions from a dedicated community of professionals. Our platform provides a seamless experience for finding reliable answers from a network of experienced professionals.
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;
}
Thanks for using our platform. We're always here to provide accurate and up-to-date answers to all your queries. Thank you for your visit. We're committed to providing you with the best information available. Return anytime for more. Discover more at Westonci.ca. Return for the latest expert answers and updates on various topics.