为什么我的程序没有在firefox浏览器中执行?

时间:2016-02-17 18:35:35

标签: javascript html

<!DOCTYPE html>

<head>
  <title> battleship games 1-d </title>
  <meta charset="UTF-8">
</head>

<body>
  <h1> Battleship war begins</h1>
  <script language=javascript>
    var randomLoc = Math.floor(Math.random() * 5);
    var location1 = randomLoc;
    var location2 = location1 + 1;
    var location3 = location2 + 1;
    var guesses;
    var guesses = 0;
    var hits = 0;
    var issunk = false;
    while (issunk == false) {
      prompt("Ready,Aim,Fire!(enter a number between 0-6:)");
      if (guesses < 0 || guesses > 6) {
        alert("please enter a valid number");
      } else {
        guesses = guesses + 1;
      }
      if (guesses == location1 || guesses == location2 || guesses == location3) {
        alert("hit!");
        hits = hits + 1;
      } else {
        prompt("You are running out of chances");
      }
      if (hits == 3) {
        issunk == true;
        alert("you sink my battle ship");
      } else {
        alert("Miss");
      }
      var status = "You took" + guesses + "to sink my battleship" + "so you have a   accuracy of about:" + (3 / guesses);
      alert("status");

  </script>
  <p>This was my first game that was cerated in javascript</p>
</body>

这是我的代码,只有代码的html部分在浏览器中执行,并且在脚本标记内部不会在浏览器上执行。

2 个答案:

答案 0 :(得分:0)

有人忘记了一个花括号来关闭while循环。只需在脚本末尾添加一个}。

答案 1 :(得分:0)

您缺少结束括号,请参阅示例https://jsfiddle.net/x34aotm6/

<div class="container">
  <div class="bg" style="position:absolute;top:0;left:0;width:50%;height:500px;">
  <div class="row">
    <div class="col-lg-6">
      <h1>Test Content col-lg-6</h1>
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi aliquam mauris quis arcu pretium, quis lacinia odio lobortis. Mauris a tellus turpis. Fusce pretium enim eget lorem sodales lacinia non sed metus. Donec quis varius enim. Phasellus vitae sapien congue, convallis justo eu, pharetra turpis. Sed a augue et nulla sodales aliquet. Aenean id nulla vitae odio tincidunt placerat. Etiam pharetra, lorem a sollicitudin ultricies, elit lectus vehicula lectus, ac molestie risus nibh quis velit. Sed accumsan aliquet orci eu commodo. Nam consectetur lacinia tempus.</p>
    </div>
    <div class="col-lg-6">
      <h1>Test Content col-lg-6</h1>
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi aliquam mauris quis arcu pretium, quis lacinia odio lobortis. Mauris a tellus turpis. Fusce pretium enim eget lorem sodales lacinia non sed metus. Donec quis varius enim. Phasellus vitae sapien congue, convallis justo eu, pharetra turpis. Sed a augue et nulla sodales aliquet. Aenean id nulla vitae odio tincidunt placerat. Etiam pharetra, lorem a sollicitudin ultricies, elit lectus vehicula lectus, ac molestie risus nibh quis velit. Sed accumsan aliquet orci eu commodo. Nam consectetur lacinia tempus.</p>
    </div>
  </div>
</div>