无法获得警报或确认可以在javascript中工作

时间:2018-08-16 19:57:30

标签: javascript jquery html

编辑:感谢大家,它已经修复了(:非常感谢

我无法获得警报,确认或提示,但这里是我的代码(不是完整的代码,但开头是我无法工作的部分,因此我将其保留下来并省略了代码的末尾,所以在这里是:

var warGood = 0
    var warEvil = 0
    var life

    var mh = false

    var document.Gold = 1000;
    var gems = 1000;
    var lb = false
    var Stellar_grenades  = 0
    var Cosmic_grenades = 0;
    var Level = 1    
    var person
    
    person = prompt("please enter your name", "Specimen")

    if (person != null) {
      if (person == "shit") {
        alert("Really? choose a new MORE APPROPRIATE name", "Ok ill choose a new More APPROPRIATE name")
      }

    else if (person != "shit"){
      if (person != null) {alert(
        "welcome "  + person + " to the universe")
      }
    }

    alert(
    "not too long ago your planet was blown up in the midst of a universal war, you luckily survived and fled to another planet");
    alert("You are now here, On Planet Vecron, Here you will build up your    base,")
    alert("then you can eventually go on missions to distant planets,")
    alert("Upon Reaching the final mission, you will notice one thing")
    alert ("Your Not on a new planet, but rather a new universe,")
    alert("this universe holds the Key to cosmic peace,")
    alert(" This Key is the Community Pendant")
    
    life = confirm("Do you have what it takes to get this pendant and end the universal war?")
    
     if (life == true) { 
      alert("Thank you " + person + "You will make a fine adventurer");
      alert("gold is the main currency Here on vecron")
      alert(" If you want anything it can buy it, with a few exceptions")
      alert("You cant buy the Community Pendant")
      alert(" Or gems Or the special 12 summoners tools")
      alert(" Shh the summoners tools will be talked about later")
      alert("saving your game is important,")
      alert("To Open the shop Press S")
      alert("To Save Press F")
      alert("To get money you simply have to press the money button!")
      alert("The Ding Is to make sure you actually have good reflexes while in missions.")
      alert("You get missions after you unlock the mission hall")
      alert("then you can start the first journey on your many adventures")
      document.write("you have " + document.Gold + " Gold and " + gems + " gems")
      alert("Go Get that Pendant and save the world")
<img src = "logo.png" alt = "logo">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">

我真的无法弄清楚,它在几周前运行良好,然后我休息了一会儿,又回到原来的状态,突然之间它不再工作了

1 个答案:

答案 0 :(得分:0)

Document.gold不是有效的JS。如果要使用全局变量,则可以只使用var关键字。这会将它们添加到全局范围。像这样:

var gold = 1000;

记录DOM API的主要对象。 HTML文档被解析并以JS表示形式加载到内存中。然后,您可以修改DOM,这将导致UI更新。您已经在以下代码中进行了更改(更改了一点):

var gold = 1000;
var gems = 25;

document.write("you have " + gold + " Gold and " + gems + " gems")