在Javascript中增加变量不起作用?

在Javascript中增加变量不起作用?,javascript,Javascript,我使用变量创建了一个基本分数计数器 基本上,当您单击一个框时,如果变量findbomb等于函数选择的参数,然后它会说你赢了,应该在变量得分中加1,但是如果变量findbomb与参数num不同,那么if会说你输了,并从得分中减去1 但是出于某种原因,即使我使用score++来增加变量,它也拒绝这样做,并且在Chrome的developers菜单中没有出现错误 <!doctype html> <html> <head> <title>Assi

我使用变量创建了一个基本分数计数器

基本上,当您单击一个框时,如果变量
findbomb
等于函数选择的参数,然后它会说你赢了,应该在变量
得分中加1,但是如果变量
findbomb
与参数
num
不同,那么if会说你输了,并从得分中减去1

但是出于某种原因,即使我使用
score++
来增加变量,它也拒绝这样做,并且在Chrome的developers菜单中没有出现错误

<!doctype html>
<html>
<head>

    <title>Assignment</title>

    <style>
        body{background:black;}


        #game{width:1282px;
              position:absolute;top:15%;left:50%;
              margin-left:-642px;}

        #background{width:1282px;}

        #covered{width:1282px;
                 position:absolute;left:50%;top:70%;
                 margin-left:-642px;
                 z-index:100;}

        #filled{width:1282px;
                position:absolute;top:70%;
                z-index:50;}

        #box0{position:absolute;;left:20%;}

        #box1{position:absolute;left:60%;}


        .bombonleft{position:absolute;left:20%;}
        .blankonright{position:absolute;left:60%;}


        .blankonleft{position:absolute;left:20%;}
        .bombonright{position:absolute;left:60%;}

        #rules{width:500px;
               text-align:center;
               background:red;
               position:absolute;top:10%;left:50%;
               margin-left:-250px;
               z-index:300;
               display:none;}


        #feedback{position:absolute;left:50%;top:10%;
                  margin-left:-300px;
                  width:600px;
                  height:auto;
                  font-size:200%;
                  font-family:sans-serif;
                  text-align:center;
                  background:red;
                  display:none;}

        #scores{position:absolute;top:10%;left:5%;
               width:50px;
               text-align:center;
               font-size:300%;
               font-family:sans-serif;
               background:red;}

        #timer{position:absolute;top:30%;left:50%;
               margin-left:-236px;}

        #countdown{width:300px;
                   text-align:center;
                   position:absolute;
                   left:50%;
                   top:35%;
                   font-family:sans-serif;
                   font-size:1000%;
                   margin-left:-150px;
                   color:red;
                 }

        #title{text-align:center;
               font-family:sans-serif;
               font-size:300%;
               color:red;
               }
        #finder{background:red;}

        #new{background:red;}
    </style>


</head>

<body> 
    <div id="title">
        <p>Find the Bomb!</p>
    </div>

    <div id ="game">


      <div id="covered">  
            <img id="box0" src="closed.png" onclick="choose(0);">
            <img id="box1" src="closed.png" onclick="choose(1);">
        </div>

        <div id="filled">
          <img id ="bomb" class="bombonright" src="bomb .png">
          <img id="blank" class="blankonleft" src="empty.png">
      </div>

       <div id="background">
         <div id="scores"> 2 </div>
            <img id="backround"src="new background.png">    
       </div>

       <div id="buttons">
         <button id="Restartbtn" onclick="start();">Restart</button>
         <button id="Rulesbtn" onclick = "showrules();">?</button>
      </div>

        <div id="rules">
            <p> You awake to find yourself locked in this room with two boxes at your feet.</p>
            <p> A voice comes over a speaker and states "Welcome, you have been chosen to take part in a little game. At your feet you will find two boxes. One is empty and the other contains a enough explosives to reduce you to dust. The aim of the game is simple find the bomb.</p>
            <p> However, there are some rules</p>
            <p> Firstly you must make a choice within 5 seconds , otherwise the bomb explodes. There is a timer that counts down so be ware<p>
            <p> You may only choose one box </p>
            <p> Choose correctly and you may advance to the next round <p>
            <p> If you survive a round you will get a point ,once you have 5 you will be set free <p>
            <p> However if you fail to find the bomb , you will lose a point. Once you score hits -5 , the bomb will detonat<p>
            <p> The game begins as soon as you press close on this message, if you need to select it again press the "?" button<p>

            <button onclick="hiderules();"> CLOSE </button>
        </div>

      <div id="feedback">
            You lost! <br>Fortunately this bomb was a fake!
        </div>
<div id="timer">
      <img src="timer.png">
    </div>

        <div id="countdown">
            2:00
        </div>

        <div id="finder">
        fdafdsfa
        </div>

      <div id="new">
        2ffdaj
        </div>

    </div>

    <script>
        var findbomb=1;
        var clickable = false;
        var score = 0;

        window.onload = start();findme();newscore();

        function findme()
            {document.getElementById('finder').innerHTML = findbomb;}   

        function newscore()
            {document.getElementById('new').innerHTML = score;};

        function start()
            {score=0;
             showscore();
             setup();};

        function showscore()
            {document.getElementById('scores').innerHTML= score;};

        function hidebox()
            {document.getElementById('box0').style.display = "block";
             document.getElementById('box1').style.display = "block";};

        function hidefeedback() 
            {document.getElementById('feedback').style.display =  "none";};

        function showbfeedback()
            {document.getElementById('feedback').style.display = "block";
             setTimeout(setup, 1000);
            };

        function showrules()
            {document.getElementById('rules').style.display = "block";};

        function hiderules()
            {document.getElementById('rules').style.display = "none";};

        function play()
            { findbomb = Math.floor(Math.random()*2);

              if (findbomb == 0)
                {document.getElementById('bomb').setAttribute("class", "bombonleft");
                 document.getElementById('blank').setAttribute("class", "blankonright");}

              else if (findbomb == 1)
                {document.getElementById('bomb').setAttribute("class", "bombonright");
                 document.getElementById('blank').setAttribute("class", "blankonleft");}

             clickable=true;

            };

        function setup()
            {hidefeedback();
             hidebox();
             play();};

        function choose(num)
            {if (clickable = true)
                {document.getElementById('box'+num).style.display = "none";

                    if(findbomb ==num)
                        {document.getElementById('feedback').innerHTML = "You Win"; score++;}
                    else if (findbomb != num)
                        {document.getElementById('feedback').innerHTML ="You lose, fortunately that one was a fake!";score--;};

                    setTimeout(showbfeedback, 1000);
                    clickable= false;   
                }
            }


    </script>
</body>
</html>

分配
正文{背景:黑色;}
#游戏{宽度:1282px;
位置:绝对位置;顶部:15%;左侧:50%;
左边距:-642px;}
#背景{宽度:1282px;}
#覆盖{宽度:1282px;
位置:绝对位置;左侧:50%;顶部:70%;
左边距:-642px;
z-索引:100;}
#填充{宽度:1282px;
位置:绝对;顶部:70%;
z-索引:50;}
#box0{位置:绝对;;左侧:20%;}
#框1{位置:绝对;左侧:60%;}
.bombonleft{位置:绝对;左侧:20%;}
.blankonright{位置:绝对;左侧:60%;}
.blankonleft{位置:绝对;左侧:20%;}
.bombonright{位置:绝对;左侧:60%;}
#规则{宽度:500px;
文本对齐:居中;
背景:红色;
位置:绝对位置;顶部:10%;左侧:50%;
左边距:-250px;
z指数:300;
显示:无;}
#反馈{位置:绝对;左侧:50%;顶部:10%;
左边距:-300px;
宽度:600px;
高度:自动;
字体大小:200%;
字体系列:无衬线;
文本对齐:居中;
背景:红色;
显示:无;}
#得分{位置:绝对;顶部:10%;左侧:5%;
宽度:50px;
文本对齐:居中;
字体大小:300%;
字体系列:无衬线;
背景:红色;}
#定时器{位置:绝对;顶部:30%;左侧:50%;
左边距:-236px;}
#倒计时{宽度:300px;
文本对齐:居中;
位置:绝对位置;
左:50%;
最高:35%;
字体系列:无衬线;
字体大小:1000%;
左边距:-150px;
颜色:红色;
}
#标题{文本对齐:居中;
字体系列:无衬线;
字体大小:300%;
颜色:红色;
}
#查找程序{背景:红色;}
#新{背景:红色;}
找到炸弹

2. 重新启动 ? 你醒来时发现自己被锁在这个房间里,脚下有两个箱子

一个声音从扬声器中传来,说:“欢迎,你被选中参加一个小游戏。在你脚边你会发现两个盒子。一个是空的,另一个盒子里有足够的炸药,可以把你炸得粉身碎骨。游戏的目的很简单,就是找到炸弹

但是,有一些规则

首先,你必须在5秒内做出选择,否则炸弹会爆炸。有一个计时器会倒计时,所以一定要小心 您只能选择一个框

选择正确,您可以进入下一轮 如果你通过了一轮,你将得到一分,一旦你得到5分,你将被释放 但是如果你找不到炸弹,你将失去一分。一旦你命中-5,炸弹将引爆 当您按下此消息的“关闭”按钮时,游戏立即开始,如果需要再次选择,请按“?”按钮 接近 你输了!幸好这枚炸弹是假的! 2:00 fdafdsfa 2ffdaj var findbomb=1; var clickable=false; var得分=0; window.onload=start();findme();newscore(); 函数findme() {document.getElementById('finder').innerHTML=findbomb;} 函数newscore() {document.getElementById('new').innerHTML=score;}; 函数start() {得分=0; showscore(); setup();}; 函数showscore() {document.getElementById('scores')。innerHTML=scores;}; 函数hidebox() {document.getElementById('box0').style.display=“block”; document.getElementById('box1').style.display=“block”;}; 函数hidefeedback() {document.getElementById('feedback').style.display=“none”;}; 函数showbfeedback() {document.getElementById('feedback').style.display=“block”; 设置超时(设置,1000); }; 函数showrules() {document.getElementById('rules').style.display=“block”;}; 函数hiderules() {document.getElementById('rules').style.display=“none”;}; 函数播放() {findbomb=Math.floor(Math.random()*2); if(findbomb==0) {document.getElementById('bomb').setAttribute(“class”,“bombonleft”); document.getElementById('blank').setAttribute(“class”,“blankonright”);} else if(findbomb==1) {document.getElementById('bomb').setAttribute(“class”,“bombonright”); document.getElementById('blank').setAttribute(“class”,“blankonleft”)
window.onload = start;
window.onload = function(){
    start();
};