Create a loop that only stops when all 4 characters have been guessed

Can some one help me here pls. I dont know what i have wrong. i already look hours…

var password = 4;
var correctGuesses = 0;


while(correctGuesses < 4)	{
    var outcome = Math.ceil(Math.random() * 3);
    
    if(outcome === 1)	{
        correctGuesses++;
        console.log('Found' + correctGuesses + 'characters');
        
    }
	else if(outcome === 2)	{
        correctGuesses = 0;
        console.log('Starting over');
    }
    else if(outcome === 3)	{
        correctGuesses = correctGuesses;
    }
}
	if(correctGuesses === password)	{
        console.log('Terminal hacked!');
    }

Welcome to our community!

Change the quotes in the console.log(“Terminal hacked!”):

Output

Code is incorrect

You guessed some characters correctly, but failed to do the right thing!

didn’t change anything :confused:

Note - you shouldn’t use var. You should use let or const only.

I would also add to what @JeremyLT said, that maybe you should add blank spaces to the console.log() output:

 console.log('Found ' + correctGuesses + ' characters');

I guess that Found1characters is not what is expected to be printed out.
That also could be a reason why the test didn’t pass.

1 Like

this is a task that should do to enter in a bootcamp, and i not arrived to that part yet. i never use let or const

this is the task:

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 so far.

Bear in mind that your program does not need to guess the password, that is not your goal!

You need to create a loop that only stops when all 4 characters have been guessed. On each loop iteration you need to calculate a random number between 1 and 3, which will correspond to each of the bellow scenarios:

  1. You guessed one character correctly, which increases correctGuesses by 1 and prints the message ‘Found X characters’ (where X is replaced with the current number of correct guesses).

  2. You guessed 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.

  3. You guessed incorrectly, but have not been detected yet, correctGuesses is kept with the same value.

Once the password is cracked (that is, correctGuesses has a value of 4) you should print the message ‘Terminal hacked!’.

Make sure all the messages in your code are in the correct format in order to advance!

i realy dont know, what to do :confused:

Ok, but you should never use var.


Did you fix this line yet?

1 Like

i did it, it worked! but can you explaime why i need to add that 2 blank spaces?
And thank you!!! really!

it worked! thank you!!!

1 Like

Read instruction number one again:...prints the message ‘Found X characters’ ...
You must get the same words and spaces order: “Found”, then a blank space, then “X”, then a blank space…

for a pearson that never touched on aprograming language, see that error is kinda tough.
Reach this bootcamp, is becoming harder.

Thanks for the help.