A
A
Alexey L.2016-01-09 12:16:06
JavaScript
Alexey L., 2016-01-09 12:16:06

Why doesn't it work or what is the error in the code (html + js)?

Wrote the code according to the book, but it doesn't work. Tell me, please, what could be wrong?
According to the result, there should be a mini-game of a sea battle with one ship. Enter the number until you get into the ship. But when you run the written code, the script does not run. Although I did everything according to the book.
Thank you all in advance!
battleship.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    </head>
  <body>
    <h1>Play battleship!</h1>
    <script src="battleship.js"></script>
  </body>
</html>

battleship.js
var location1=3;
var location2=4;
var location3=5;
var guess;
var hits=0;
var guesses=0;
var isSunk=false;
while (isSunk == false) {
  guess=promt ("Ready, aim, fire! enter a number from 0-6:");
  if(guess<0||guess>6) {
  alert ("Please enter a valid cell number!");
  }	else {
  guesses=gusses + 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);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey S., 2016-01-09
@atale

skipped a letter =)
....guess=promPt ("Ready,....

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question