-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwar.js
More file actions
40 lines (31 loc) · 1 KB
/
war.js
File metadata and controls
40 lines (31 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
var location1 = Math.floor(Math.random()* 5);
var location2 = location1 + 1;
var location3 = location2 + 1;;
var hits = 0;
var guesses = 0;
var guess;
var IsSunk = false;
while (IsSunk == false){
guess = prompt("Game On!!!, enter a number between 0 and 6");
if (guess < 0 || guess > 6){
alert("enter a valid number");
} else {
guesses = guesses + 1
if (guess == location1 || guess == location2 || guess == location3){
alert("HITS")
hits = hits + 1
if (hits == 3){
IsSunk = true;
alert("You sank the battleship")
}
if (location1 == location2 || location2 == location3 || location1 == location3){
alert("MISS!, enter a different value")
}
} else {
alert("MISS!");
}
}
}
var result = "it took " + guesses + " guesses to sank a battleship " +
" which means a shooting accuracy of " + (3/guesses);
alert(result)