【发布时间】:2021-08-03 12:46:56
【问题描述】:
我是编码新手,这是我的第一篇文章。非常感谢您提供的任何帮助。我正在尝试创建一个级别计算系统,您可能会在 RPG 中看到具有不同统计数据的角色。当我以不同的值运行程序时,我收到以下消息:
意外的标记“this”
我已将出现错误消息的代码部分放在星号中。
const Sean = {
fullName: `Sean`,
attack: 1,
strength: 1,
defense: 38,
hitpoints: 40,
prayer: 15,
range: 98,
magic: 99,
calcCombatLevel: function () {
this.Meleelvl = .25 * (this.defense + this.hitpoints + Math.floor((this.prayer / 2))) + ((13 / 40) * (this.attack + this.strength));
this.magiclvl = .25 * (this.defense + this.hitpoints + Math.floor((this.prayer / 2))) + ((13 / 40) * (this.magic * (3 / 2)));
this.rangelvl = 0.25 * (this.defense + this.hitpoints + Math.floor((this.prayer / 2))) + ((13 / 40) * (this.range * (3 / 2)));
if ((this.attack + this.strength) > ((2 / 3) * this.magic) && (this.attack + this.strength) > ((2 / 3) * this.range)) {
return this.meleelvl;
}
// **********************************
else if ((2 / 3) this.magic > (this.attack + this.strength) && (this.magic >** this.range)) {
return this.magiclvl;
}
else if((2 / 3) * this.range > (this.attack + this.strength) && (this.range > this.magic)) {
return this.rangelvl;
}
}
}
Sean.calcCombatLevel();
console.log(Math.floor(Sean.lvl));
【问题讨论】:
-
在 (2 / 3) 之后需要一个星号来表示乘法。
-
这是哪种编程语言?请edit澄清,并添加标签。
-
感谢您的帮助!!!我输入了星号,但现在我输入的任何值在我运行程序时都会得到消息而不是数字。我正在使用 Javascript
-
请将其作为一个单独的问题发布,并包含完整的回溯。现在,我看不到你在哪里初始化
Sean.lvl。 -
感谢所有发帖的人。我意识到我没有问最好的问题,以后我会更好地遵循论坛指南。艾莉亚·麦卡锡,你是对的,我在 (2/3) 之后错过了星号
标签: javascript unexpected-token