0

I'm trying to set a battleship game as a website for an assignment. In the assignment, prompt() is used.

I tried assigning a new value to the variable guess. That didn't work either. Here is what I have so far:

let location1 = 3; 
let location2 = 4;
let location3 = 5;

let guess;

let hits = 0;

let guesses = 0;

let isSunk = false;

while (isSunk == false) {
    guess = prompt("Ready, aim, fire! (enter a number 0-6):");
    if (guess < 0 || guess > 6) {
        alert("Please enter a valid cell number!");
        } else {
            guesses = guesses + 1;
    }
}

The game should provide with feedback of whether the ship has been hit or not, but all it does is prompting the "Ready, aim, fire! (enter a number 0-6):" message again and again. When tested with the console, it will give ReferenceError: prompt is not defined.

Lucia
  • 11
  • 1

1 Answers1

0

If it shows prompt is not defined then add this code at the start of the program:

const prompt = require("prompt-sync")();
user16217248
  • 3,119
  • 19
  • 19
  • 37