由于if else块,JS脚本不起作用

时间:2014-04-11 12:16:21

标签: javascript android

我被禁止了,不能再提问了。为了纠正这个问题,我用这个文本块编辑了我最低调的线程。我的意图是永远不会用愚蠢的问题阻止Stackoverflow或者从社区中榨取,但我在某些时候做过。通过阅读这个有用的帖子How to Ask Questions the Smart Way,我意识到了自己的伤害。现在我希望社区能够原谅我的无意伤害。谢谢

我正在制作一个简单的原型计算器,用于在特定条件下进行各种损伤计算的游戏。因为这个游戏涉及一些精确度,我们经常需要现场计算,我已经决定尝试将其转换为使用Appsgeyser的Android手机的实际应用,而不是上网到某个虚拟网页我' d设置基本表格计算器。

然而,我的javascript技能也是基本的,但足够我的这个小项目。后来我意识到我的语法有多糟糕,为什么人们批评它,但由于我不知道如何改进它,我只能让人们帮我找出错误。

IF / ELSE块失败,我看不清楚原因。

<script>
function showDiv() {
var dmgpct = 0;
var dmginc2 = 0.00;
var arminc = 0.00;
var critinc = 0.00;
var critinc2 = 0;
var splashdmg2 = 0;
var splashinc = 0.00;
var critchance = parseInt(document.getElementById('critchance').value);
var critdmg = document.getElementById('critdmg').value;
var splashdmg = parseInt(document.getElementById('splashdmg').value);
var armor = document.getElementById('armortype').value;
var armoramount = document.getElementById('armoramt').value;
var damage = document.getElementById('dmgtype').value;
var min = parseInt(document.getElementById('mindmg').value);
var max = parseInt(document.getElementById('maxdmg').value);
var dmginc = parseInt(document.getElementById('dmginc').value);
var dmg_done = Math.floor(Math.random() * (max - min + 1) + min);
var try_crit = Math.floor(Math.random() * (100 - critchance + 1) + critchance);

document.getElementById('result').style.display = "block";

if(damage == "Normal" && armor == "Medium")
{
dmginc2 = parseFloat(dmginc * 0.01 + 1.50);
arminc = parseFloat(dmginc2 - armoramount * 0.05);
dmgpct = Math.floor(dmg_done * arminc);
document.getElementById('test').innerHTML = "Damage Roll: " + dmg_done;
document.getElementById('test2').innerHTML = "Damage Boost: " + arminc.toFixed(2) + "%";
    if (try_crit <= critchance)
    {
    critinc = parseFloat(critdmg * 0.01);
    critinc2 = parseInt(dmgpct*critinc);
    splashinc = parseFloat(splashdmg * 0.01);
    splashdmg2 = Math.floor(critinc2 * splashinc);
    document.getElementById('test3').innerHTML = "<b>CRITICAL DAMAGE: " + critinc2 + "</b>";
    document.getElementById('test4').innerHTML = "<b>Splash Damage Dealt: " + splashdmg2 + "</b>";
    }
    else
    {
    splashinc = parseFloat(splashdmg * 0.01);
    splashdmg2 = Math.floor(dmgpct * splashinc);
    document.getElementById('test3').innerHTML = "<b>Total Damage Dealt: " + dmgpct + "</b>";
    document.getElementById('test4').innerHTML = "<b>Splash Damage Dealt: " + splashdmg2 + "</b>";
    }
}
else if(damage == "Normal" && armor == "Heavy")
{
dmginc2 = parseFloat(dmginc * 0.01 + 0.50);
arminc = parseFloat(dmginc2 - armoramount * 0.05);
dmgpct = Math.floor(dmg_done * arminc);
document.getElementById('test').innerHTML = "Damage Roll: " + dmg_done;
document.getElementById('test2').innerHTML = "Damage Boost: " + arminc.toFixed(2) + "%";
    if (try_crit <= critchance)
    {
    critinc = parseFloat(critdmg * 0.01);
    critinc2 = parseInt(dmgpct*critinc);
    splashinc = parseFloat(splashdmg * 0.01);
    splashdmg2 = Math.floor(critinc2 * splashinc);
    document.getElementById('test3').innerHTML = "<b>CRITICAL DAMAGE: " + critinc2 + "</b>";
    document.getElementById('test4').innerHTML = "<b>Splash Damage Dealt: " + splashdmg2 + "</b>";
    }
    else
    {
    splashinc = parseFloat(splashdmg * 0.01);
    splashdmg2 = Math.floor(dmgpct * splashinc);
    document.getElementById('test3').innerHTML = "<b>Total Damage Dealt: " + dmgpct + "</b>";
    document.getElementById('test4').innerHTML = "<b>Splash Damage Dealt: " + splashdmg2 + "</b>";
    }
}
else if(damage == "Normal" && armor == "Light")
{
dmginc2 = parseFloat(dmginc * 0.01 + 1.00);
arminc = parseFloat(dmginc2 - armoramount * 0.05);
dmgpct = Math.floor(dmg_done * arminc);
document.getElementById('test').innerHTML = "Damage Roll: " + dmg_done;
document.getElementById('test2').innerHTML = "Damage Boost: " + arminc.toFixed(2) + "%";
    if (try_crit <= critchance)
    {
    critinc = parseFloat(critdmg * 0.01);
    critinc2 = parseInt(dmgpct*critinc);
    splashinc = parseFloat(splashdmg * 0.01);
    splashdmg2 = Math.floor(critinc2 * splashinc);
    document.getElementById('test3').innerHTML = "<b>CRITICAL DAMAGE: " + critinc2 + "</b>";
    document.getElementById('test4').innerHTML = "<b>Splash Damage Dealt: " + splashdmg2 + "</b>";
    }
    else
    {
    splashinc = parseFloat(splashdmg * 0.01);
    splashdmg2 = Math.floor(dmgpct * splashinc);
    document.getElementById('test3').innerHTML = "<b>Total Damage Dealt: " + dmgpct + "</b>";
    document.getElementById('test4').innerHTML = "<b>Splash Damage Dealt: " + splashdmg2 + "</b>";
    }
}
</script>

1 个答案:

答案 0 :(得分:0)

使用格式良好且缩进的代码,您可以轻松地看到函数末尾缺少右括号...

独立于布局,你应该真正提高它的可读性,这是难以阅读的。