为什么JavaScript会随机添加'/1';到URL栏的末尾?

为什么JavaScript会随机添加'/1';到URL栏的末尾?,javascript,firefox,Javascript,Firefox,所以,我和几个朋友正在用JavaScript制作一个视频游戏(文本冒险)。在这个游戏中,你四处与怪物战斗。它以战斗开始,但当你赢了,它会在URL的末尾随机添加“/1”。这很奇怪,因为window.location从未出现在程序中。以下是出现问题时执行的代码: function Places() { location = 1 answer = prompt('Where do you go now? You have ' + totalGold + ' gold, and ' + hitPoi

所以,我和几个朋友正在用JavaScript制作一个视频游戏(文本冒险)。在这个游戏中,你四处与怪物战斗。它以战斗开始,但当你赢了,它会在URL的末尾随机添加“/1”。这很奇怪,因为
window.location
从未出现在程序中。以下是出现问题时执行的代码:

function Places() {
location = 1
  answer = prompt('Where do you go now? You have ' + totalGold + ' gold, and ' + hitPoints + ' health.', 'Town, Plains, Swamp, Menu').toUpperCase()
  switch (answer) {
    case 'TOWN':
      if (aabeaDestroysTown === 0) {
        alert('You walk into town, where there is a marketplace and an inn.')
        InTown()
      } else {
        alert('As you near the outskirts of town, you notice the stream of people leaving town. Then you notice that the entire place is now just a gigantic blast crater. Somebody blew it up!!! You decide to investigate, and walk over to the stream of people.')
        alert('When you reach the people, they all say this person named A\'Abea had just come to town and started fires all over, and then used some weird, magical powers to blow up Smatino.')
        alert('You are sure this A\'Abea is the same as the one who you met in the swamp, and wish you had used some \'weird, magical powers\' to blow him up')
        alert('You race back to the swamp, and see him from a distance. You can\'t, however, blow him up. There are too many vines in the way. So, you follow him. You see a large tower in the distance, and finally, after a few hours, reach it at night. You see A\'Abea enter, and then, as the gate is clanging down above him, you slide under it and manage to get in.')
        inTower()
      }
      break;
等等。您只会在一瞬间看到
prompt()
框,然后它进行随机加法

错误消息:
更奇怪的是,它似乎只在Firefox中测试时才这样做。

这是因为您正在将
窗口位置设置为
1
。除非您想更新页面URL,否则不要这样做


默认情况下,在全局
窗口
对象上设置变量。如果要在函数中设置名为
location
的局部变量,请使用
var location=1

这是因为您要将
window.location
设置为
1
。除非您想更新页面URL,否则不要这样做


默认情况下,在全局
窗口
对象上设置变量。如果要在函数中设置名为
location
的局部变量,请使用
var location=1

确实,您没有注意到全局范围内代码顶部的
location=1
变量(无“var”)?更改该变量的名称,它就被解决了。或者至少使它成为一个
var位置
var位置
在最顶端“变量位置
在最顶端”在什么的顶端?当然不在您发布的示例的顶部。代码的开头真的,您没有注意到全局范围内代码顶部的
location=1
变量(无“var”)?更改该变量的名称,它就被解决了。或者至少使它成为一个
var位置
var位置
在最顶端“变量位置
在最顶端”在什么的顶端?当然不是在您发布的示例的顶部。代码的最底层
/*
Exception: out of memory
*/