mercredi 27 avril 2016

Javascript variable with InnerHtml not working

I'm coding a game and in the game when you die I want a specific game over text to be displayed according to the score using innerHTLM and if/else if

I followed some tuts but it doesn't seem to work and don't know why.

Here's the code :

<div id="game-over">
      <h3><font color="orange">Tu as courus <span id="score"></span> mètres.</font></h3>
      <font color="orange"><h1 id="customegotext">Error text not found</h1></font>
      <a href="javascript:void(0)" class="button restart">Ressayer ?</a>
    </div>
  </div>
  <script>
    var scoretext;
    if ("score" < 45) {
        scoretext = "Text1";
    } else if ("score" > 100 ) {
        scoretext = "Text2";
    } else if ("score" > 500 ) {
        scoretext = "Text3";
    } else if ("score" > 750 ) {
        scoretext = "Text4";
    }
    document.getElementById("customegotext").innerHTML = scoretext;
</script>

More details :

  • The variable "score" is calculater in a separate .js file specifed in the index.html ( file where the error is present ) by this line of code

<script type="text/javascript" src="ljdm.js"></script>

  • The game works perfectly ( .html, .js and .css are correctly related by code )

  • I'm a beginner into programming

Thanks for helping me !

Aucun commentaire:

Enregistrer un commentaire