2014-10-28 51 views
-1

当我运行这段代码时,我应该不会收到任何错误,但是我和它的右边是那些波浪形的括号。我已经改变了的东西和移动的东西,改变了代码,但这个错误是永远存在的:为什么我在squigly括号旁出现错误?

var name = prompt("What is your name?"); 
var bosshp = 150; 
var playhp = 100; 
alert("You are going to fight a boss"); 
alert("You have 100hp while the boss has 150hp, you deal between 1 and 10 damage while he does between 1 and 15 damage."); 
alert("You have two actions and two special abilities. Your moves are block, and attack. Blocking heals you for 5 while attacking attacks...Your special abilities are crit chance and dodge chance. There is a 25% chance to deal double damage and a 15% chance that you will dodge the bosses attack!"); 
alert("Ok " + name + ", You have to fight Gorlock, the monkey king. "); 
do 
{ 
    var q = prompt("What will be your first move?\nEnter either 'block' or 'attack'"); 
    if (q === "block") 
    { 
     playhp = playhp + 5; 
    } 
    else if (q === "attack") 
    { 
     function attack(); 
    } 
} 
while (bosshp >= 0 || playhp >= 0); 


function attack() { 
    if ((Math.floor((Math.random() * 100) + 1)) < 16) { 
     bosshp = bosshp - (Math.floor((Math.random() * 10) + 1) * 2); 
    } else { 
     bosshp = bosshp - (Math.floor((Math.random() * 10) + 1)); 
    } 
} 
+0

仅供参考工具,说卷曲y括号,而不是波形括号(尽管我知道你的意思,其他人可能不会)。 – 2014-10-28 02:10:10

+1

哪个花括号?我们无法看到您的屏幕,也看不到任何大括号 – jasonscript 2014-10-28 02:22:49

回答

0

,因为你定义当你真正称之为

else if (q === "attack") 
{ 
    function attack(); 
    ^^^^^^^^ 
} 

删除功能的功能

else if (q === "attack") 
{ 
    attack(); 
} 

使用像http://www.jshint.com/http://www.jslint.com/

+0

+1。请注意,“函数”关键字用于定义一个函数,而不是调用它。除了使用JSHint,我还是建议在编写游戏之前学习JS语法的基础知识(这是一个友好的建议)。 – Greg 2014-10-28 02:12:52

+0

http://jsfiddle.net/wtjo7rmw/我的代码不会停止,除非两个hp值都是负数。为什么是这样,我怎么得到我的|| (或)函数 – ShowmenTv 2014-10-28 02:40:02

+0

,因为它表示如果这个OR大于零。它并没有说这个AND是否大于零。代码运行完全正确,你需要而不是OR – epascarello 2014-10-28 03:59:57

相关问题