警报对话框,用于警报统计信息,在代码的最后,在循环结束后不会弹出

The alert dialog box, for the alert stats, at the very end of the code is not popping up after the loop ends

你们能帮帮我吗?我不知道我的代码有什么问题。在我的循环结束后,最后的警报对话框(警报统计信息)没有弹出。这是我的代码:JavaScript

var location1 = 3;
var location2 = 4;
var location3 = 5;
var guess;
var hits = 0;
var guesses = 0;
var isSunk = false;
while (isSunk == false) {
    guess = prompt("Ready, aim, fire! (Enter a number from 0-6):");
    if (guess < 0 || guess > 6) {
        alert("Please enter a valid cell number!");
    } else {
        guesses = guesses + 1;

        if (guess == location1 || guess == location2 || guess == location3) {
            alert("HIT!");
            hits = hits + 1;
            if (hits == 3) {
                isSunk == true;
                alert("You sank my battleship!");
            }
        } else {
            alert("MISS");
        }
    }
}
var stats = "You took " + guesses + " guesses to sink the battleship, " + "which means your shooting accuracy was " + (3/guesses);
alert(stats); 

问题是这样的:

isSunk == true;

不是将 isSunk 重新分配给 true,而是将其与 true

进行比较

将其更改为:

isSunk = true;