raquelmontalvao Posted March 5, 2023 at 06:34 PM Report Share #630299 Posted March 5, 2023 at 06:34 PM O enunciado é este: <Hacking Task #2> Congratulations, you now know the *very* basics of the JavaScript language! To proceed on your mad journey from programming n00b to full-fledged <Code Cadet>, you must now work alongside fSociety's ultra dope hacking crew and show them your awesome recently acquired skills in a series of <Hacking Tasks>. For this task you'll need to gain access to a target's account, which is password protected. We know the password is only four characters long, but we have no idea of what it looks like. With today's computing power, brute-forcing weak passwords is not that hard and, as in any brute-force technique, it only requires time and luck. Instructions 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! Fiz o código várias vezes mas dá sempre erro. O que tenho atualmente é este: var correctGuesses = 0; var password= 4; while (correctGuesses <4) { var guess = Math.ceil (Math.random()*3); if (guess===1) { correctGuesses++; console.log('Found'+'' + correctGuesses +''+'characters'); } else if (guess===2) { correctGuesses=0; console.log('Starting over'); } else if (guess===3) { correctGuesses= correctGuesses; } if (correctGuesses === password) { console.log ('Terminal hacked'); } } Resposta: >>>>Code is incorrect You guessed some characters correctly, but failed to do the right thing! Alguém me consegue ajudar? Link to comment Share on other sites More sharing options...
Zex Posted March 5, 2023 at 07:02 PM Report Share #630300 Posted March 5, 2023 at 07:02 PM A função aleatória está a gerar entre 0 e 3 em vez de 1 e 3. Link to comment Share on other sites More sharing options...
raquelmontalvao Posted March 5, 2023 at 07:24 PM Author Report Share #630303 Posted March 5, 2023 at 07:24 PM Em 05/03/2023 às 19:02, Zex disse: A função aleatória está a gerar entre 0 e 3 em vez de 1 e 3. Obrigada! Já experimentei com: Math.floor(Math.random() * 3) + 1; Mas dá outro erro: Not sure how you can calculate a random number between 1 and 3 in such a way Socorroooo 😱 Link to comment Share on other sites More sharing options...
Zex Posted March 6, 2023 at 07:52 PM Report Share #630338 Posted March 6, 2023 at 07:52 PM Está certo mas os correctores automáticos são muito limitados. Experimenta colocar noutra ordem: 1+Math.floor(3*Math.random()); Link to comment Share on other sites More sharing options...
raquelmontalvao Posted March 6, 2023 at 09:47 PM Author Report Share #630340 Posted March 6, 2023 at 09:47 PM Já percebi que sim... Experimentei agora: 1+Math.floor(3*Math.random()); Mas mesmo assim aparece: Code is incorrect You guessed some characters correctly, but failed to do the right thing! Não consigo perceber o que está "errado" Link to comment Share on other sites More sharing options...
raquelmontalvao Posted March 6, 2023 at 10:33 PM Author Report Share #630342 Posted March 6, 2023 at 10:33 PM Consegui! O problema estava nos espaços 😑 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now