Loading...
Помощь по скриптам | Помогите с морским боем! (бесплатно)
Здорова ребята, и так, я не шарю в js, ну надеюсь вы поможете с кодом, это нужно девушке моего брата, она живет в Америке!
Это ей задали с программирования, в школе!
Надеюсь вы поможете!

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Battleship Game</title>
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body>
<h2>World of Warships! <br /> </h2>
<h3>Mini-Battleship Game.</h3>
<p id="output">Play if you are brave enough. You have 8 tries to guess the location of battleship,
<br />which is 3 units long.</p>
<p>Take a guess from 1 to 20: <input type="text" id="input" /><button id="button" onclick="game();">Shoot</button><br /></p>
<table>
<tr id="gameboard">
<th class="tile"></th>
<th class="tile"></th>
<th class="tile"></th>
<th class="tile"></th>
<th class="tile"></th>
<th class="tile"></th>
<th class="tile"></th>
<th class="tile"></th>
<th class="tile"></th>
<th class="tile"></th>
<th class="tile"></th>
<th class="tile"></th>
<th class="tile"></th>
<th class="tile"></th>
<th class="tile"></th>
<th class="tile"></th>
<th class="tile"></th>
<th class="tile"></th>
<th class="tile"></th>
<th class="tile"></th>
</tr>
</table>
<script>
var ship = Math.floor(Math.random() * 18) + 1; //create a random number
var cols = document.getElementById("gameboard");
var ship2 = ship + 1;
var ship3 = ship +1;
console.log(ship);
var attempt = 8;
var sunk = false;
var hits = 0;
var output = document.getElementById("output");
var button = document.getElementById("button");
//function

function game() {
var userGuess = +document.getElementById("input").value;
document.getElementById("input").value = "";
attempt -= 1;
if (attempt != 0 && !sunk){
if (userGuess != NaN && typeof userGuess && "string" && userGuess != ""){
output.innerHTML = "Try again! Enter a valid number only. You have " + attempt + " attemps left";
if (userGuess == ship){
hits++;
output.innerHTML = "You hit me!You have " +attempt + " attempts left";
location.style.color = "red";
}
if (hits >= 3){
sunk = true;
output.innerHTML = "Congrats!You sunk my battleship!";
button.disabled = true;
} if (sunk) {
output.innerHTML = "Ugh... You missed.You have " +attempt + " attempts left";
}}} else {
output.innerHTML = "You ran out of guesses and lost...";
button.disabled = true;
}
}
</script>
</body>
</html>
XxxDIABLOxxX , Смысле?
(...The-PhoenixX...) (07.12.2017 в 10:46)
XxxDIABLOxxX , Смысле?

В смысле что не получается?
посмеялся от души :-D
Вот что нужно

Изображение

------
51635_S71207095543.jpg (254.3 Kb)
Скачиваний: 57
блин и это в школе у них преподают?
Dobryak , Да
Онлайн: 6
Время:
Gen. 0.0986
(c) Bym.Guru 2010-2026