Hacking task - some help please

I am hours looking to this problem for a bootcamp :sob: i am nooby

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!


var correctGuesses = 0;
var password = 4;

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){
  if(correctGuesses === password){
        console.log('terminal hacked');

the error: >>>>Code is incorrect
You guessed some characters correctly, but failed to do the right thing!

some help please

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

1 Like

Well, at first glance, you aren’t outputting the expected strings. For example, if I run your code I get:

Starting over
Starting over
terminal hacked

as an example run. Those are not the strings the specs tell you to output.

Developers have to pay very close attention to details. Computers aren’t really good at “close enough”. And as a developer, you have to stick closely to the specs given to you by product owners, other developers, etc.

the strings look ok, i don´t think this is the problem

Yeah, please look again. No offense, but if I were giving this as a coding challenge for a hiring candidate, I would fail it just from looking at the output for not paying attention to detail. If I wrote an automated test for this, the output would fail. Randy explained the issues. I found five mistakes with your text output. How many can you find?

five also :sweat_smile: the space. thank you very much

Yes, the spaces, the capitalization, the punctuation… One character can break and entire system. A lot of bugs are simple typos. Even for UI, if the design team has told you, “we want this text”, you need to give them that or they will probably reject your work.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.