Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 74406

How to register a variable attribute changing and display that change in a html file

$
0
0

I am working on a bit of a platformer game. I have a variable called jumpSpeed, and it defines how high the player can jump. I also added a variable (jumpheight) that notices when the player presses the up arrow key, and displays it on the html page in a div tag. As I was bug testing, I noticed the player could hold down the up arrow and still have jumpSpeed increase, but the jumpheight variable would not notice it. Does anyone have any ideas on how to make the JS notice the jumpSpeed value increase, and then change the jumpheight variable in the div tag. Thanks.

Javascript:

var jumpheight = 0;
var jumpSpeed = 17;
function disp(str){
 document.getElementById('my_msg').innerHTML=str;
 }
 document.onkeyup = function() {
  switch (window.event.keyCode) {
      case 38:
       jumpheight++;
       disp(jumpheight)
  }};

Html:

<div style="display: inline-block;">Jump Count: </div>
 <div style="display: inline-block;" id=my_msg></div>

Viewing all articles
Browse latest Browse all 74406

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>