You know that your target’s password is 4 characters long, so you’ll just have to brute force 1 character at a time. We already declared the variable correctGuesses which you should use to keep track of how many characters you have guessed.
Now you need to create a loop that only stops when all 4 characters have been guessed. On each loop iteration there are 3 possible outcomes:
-
You guess correctly which increases correctGuesses by 1 and prints the message ‘Found X characters’ (where X is replaced with the current number of correct guesses).
-
You guess incorrectly and your target’s terminal has detected too many attempts, which resets correctGuesses to 0 and prints the message ‘Starting over’ to the console.
-
You guess incorrectly, but correctGuesses is kept with the same value.
Each outcome has the same probability of happening, but it is random.
Once the password is cracked you should print the message ‘Terminal hacked!’.
Make sure all the messages in your code are in the correct format in order to advance!
var correctGuesses = 0;
var password = [2, 4, 6, 9];
while (correctGuesses != 4)
var currentChar = Math.ceil(Math.random()*9);
switch (password[correctGuesses] === guest) {
case correctGuesses + 0:
password = [2, 4, 6, 9];
correctGuesses = 0;
console.log(‘Starting over’);
break;
case correctGuesses + 1:
password += correctGuesses;
correctGuesses++;
console.log(‘Found 1 characters’
);
break;}
console.log(‘Terminal hacked!’);