Advertisement
Guest User

Untitled

a guest
Mar 18th, 2018
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. var location1 = 3;
  2. var location2 = 4;
  3. var location3 = 5;
  4. var guess;
  5. var hits = 0;
  6. var guesses = 0;
  7. var isSunk = false;
  8.  
  9. while (isSunk == false) {
  10. guess = prompt("Ready, aim, fire! (enter a number 0-6):");
  11. if (guess < 0 || guess 6 >) {
  12. alert("Please enter a valid cell number!");
  13. } else {
  14. guesses = guesses + 1;
  15.  
  16. if (guess == location1 || guess == location2 || guess == location3) {
  17. alert("HIT!");
  18. hits = hits + 1;
  19. if (hits == 3) {
  20. isSunk == true;
  21. alert("You sunk my battleship!");
  22. }
  23. } else {
  24. alert("MISS!");
  25. }
  26. }
  27. }
  28.  
  29. var stats = "You took " + guesses + "guesses to sink the battleship, " +
  30. "which means your shooting accuracy was " + (3/guesses);
  31. alert(stats);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement