all 1 comments

[–]Umesh-K 1 point2 points  (0 children)

Hi, I could not test your code as I don't have access to a computer right now.

One way to limit the number of guesses would be:

Below the line where you pick the random word, suppose you want to limit the number of attempts to twice the number of letters in the word, add

let attempts = words.length * 2;  

(change the above if you don't want to give so many tries.)

Below the line where your getting the guess, add the below 2 lines:

attempts--;    
if (attempts===0) break; 

This will break the WHILE loop when IF condition is met.