Guessing game error. Wrote the logic perfectly, But it’s not working

The code just keep saying to insert larger number or smaller number. but don’t get it to the actual number and break, though the logic is fine in my opinion. Sometimes the console doesn’t print anything and it keeps roaming like infinite loop. Can anyone help me to understand what’s going on!??

//  Modify the guessing game you created to allow the user to guess within a dynamic range (e.g., "Guess a number between 50 and 150"). Ensure the user cannot enter a guess outside of this range.
while (true) {
  let randNumber = Math.floor(Math.random() * 101) + 50;
  let userGuess = prompt("Guess the Number: (50-150)");
  userGuess = parseInt(userGuess);
  if (!isNaN(userGuess) && userGuess >= 50 && userGuess <= 150) {
    if (userGuess == randNumber) {
      console.log("congrats! right guess");
      break;
    } else if (userGuess < randNumber) {
      console.log("Try large Number");
    } else if (userGuess > randNumber) {
      console.log("Try small number");
    }
  } else {
    console.log("Wrong input. Try a valid Number between (50-150)");
  }
}