首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >无法获得警报或确认在javascript中工作

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

Stack Overflow用户
提问于 2018-08-17 03:57:30
回答 1查看 55关注 0票数 1

编辑:感谢你们所有人,它已经被修复了(:谢谢你,太感谢了

我不能得到警告,确认或提示工作,这是我的代码(不是完整的代码,但开头是我不能工作的部分,所以我留下了它,并省略了代码的结尾,所以它是:

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">

我真的搞不懂,几周前它还运行得很好,然后我休息了一下,然后又回来了,突然它就不再工作了

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-08-17 04:31:29

Document.gold不是有效的JS。如果需要全局变量,只需使用var关键字即可。这会将它们添加到全局作用域。如下所示:

var gold = 1000;

记录DOM应用编程接口的主对象。HTML文档被解析并以JS表示形式加载到内存中。然后,您可以修改DOM,这将导致UI更新。您已经在下面的代码中做到了这一点(稍微修改了一下):

var gold = 1000;
var gems = 25;

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51884454

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档