Simple cube that moves around the container with keys I made a basic cube that can move around of container and jump too. It's basic but I want to know if I can use better methods, better formatting, or shorten the code.

This my HTML:

&lt;div class="container"&gt;
    &lt;div class="cube"&gt;
        &lt;div class="box"&gt;
    &lt;/div&gt;
&lt;/div&gt;


and this is my Javascript code with a little jQuery:

var velocity = 2;
var acceleration = 0.002;
var gravity = 2;
var key_left = false;
var key_right = false;
var key_up = false;
window.addEventListener('keydown', handleKeyDown)
window.addEventListener('keyup', handleKeyUp)


function handleKeyDown(event) {
if (event.keyCode == 65) {
    key_left = true;
} else if (event.keyCode == 68) {
    key_right = true;
} else if (event.keyCode == 87) {
    key_up = true;
}
};

function handleKeyUp(event) {
if (event.keyCode == 65) {
    key_left = false;
    velocity = 2;
    acceleration = 0.002;
} else if (event.keyCode == 68) {
    key_right = false;
    velocity = 2;
    acceleration = 0.002;
} else if (event.keyCode == 87) {
    key_up = false;
}
};

setInterval(function () {
var move = parseFloat($(".box").css("marginRight"));
var moveLimt = (parseFloat($(".cube").css("width")) - 100)

if (key_left === true &amp;&amp; move &lt; moveLimt) {
    $(".box").css("marginRight", function () {
        move += (velocity += acceleration);
        return move.toString() + "px";
    });
} else if (key_right === true &amp;&amp; move &gt; 0) {
    $(".box").css("marginRight", function () {
        move -= (velocity += acceleration);
        return move.toString() + "px";
    });
}

var jump = parseFloat($(".cube").css("height"));

if (key_up === true) {
    $(".cube").css("height", function () {
        jump += (gravity);
        if (jump &lt; 402) {
            return jump.toString() + "px";
        }
    });
} else if (key_up === false) {
    $(".cube").css("height", function () {
        jump -= (gravity);
        if (jump &gt; 98) {
            return jump.toString() + "px";
        }
    });
}
});
It looks not bad at all. However, it could look more professional, and to my not very picky eye there seem to be errors. 

HTML


There are no html-head-body tags, but every HTML document should have them. Nothing bad will happen, as modern browsers are really smart and will render your code correctly. These tags can be omitted by the HTML standards (e.g. WHATWG), but it is sort of a good style to have them always included. It will help whoever reads your code understand, that it is a document, not a part or template to be included somewhere else (if you didn't mean exactly this, of course).
The third DIV element is not closed, this is an error that will cause your HTML render not correctly. Use traditional &lt;div class="box">&lt;/div> or one-tag self-closing syntax: &lt;div class="box"/>


Javascript

At the first glance, it is nice, but it doesn't look like Javascript. To look like Javascript, it should follow, or at least visually be close to one of coding conventions. Just a couple of things to be mentioned, that come to my mind:


No header. A header really helps you (some time later), or another person, to understand what it is, what it does, who and when wrote it, what language it is written in, and many other things you may want to let the future generations know. This is just a /**/-comment block on the top of the script.
Var-group. There are two main trends with defining the variables in JS - in the header / top of the script / block / function, or right before the place they are used. I personally prefer the first approach as more traditional, and besides that you assign initial values in your script, which makes it logic to do it as you did it. Var block can be grouped under the same var expression for better readability and more laconic and easier to transfer code. E.g. 

var velocity = 2,
    acceleration = 0.002,
    //...
    key_up = false;

Separate the next logical paragraph (add listeners) with a blank line, don't keep it in the same paragraph with the "var" paragraph;
Function body is not indented well. The indentation should start with the first line of the function body. The rest is fine. E.g.

function example() {
    //first line indented
    //block opens: {
        //block indented
    //}
}
Good style is to put a block comment descriptor in front of every function to describe it.
Use strict comparison, instead of type-independent (e.g. a === b instead of a == b). This will help you avoid some issues later.
setInterval is missing the second argument - interval.
Defining function for a callback argument in the function call expression is not really a good practice, as it decreases readability and mantainability of your code and may lead to a "Callback hell", so I would recommend first define a named function and then specify it is an argument for the setInterval method. E.g. 

function example() {
    //function body
}
setInterval(example, 1000);



And, in case if there are things that you don't know and which I mentined, but didn't reference here, you know how to search the web, right? =) Reading about coding conventions and a couple of articles about the good JS coding style may defenetely help.