The square does not move JavaScript

I’m creating a game, the div with id "playerDiv" when I hit the space bar it should start going up but it doesn’t. So I would like when I hit the space bar the div would go up high.
could you help me? could you also report me the mistakes i made?

const player = document.getElementById("playerDiv");
let inc = 0;
let playerTimeOut;

function jump() {
  let x = 420 + inc; = + x;
  playerTimeOut = setTimeout(jump, 50);
window.addEventListener("keydown", checkKeyPress, false);

function checkKeyPress(key) {
  if (key.keyCode == "32") {
body {
  background-color: #222222;

#background {
  border: solid 2px #dddddd;
  width: 800px;
  height: 500px;

#playerDiv {
  background-color: #aaaaaa;
  width: 60px;
  height: 80px;
  position: relative;
  top: 420px;
  left: 10px;
<!DOCTYPE html>
<html lang="en">

  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link href="style.css" rel="stylesheet" type="text/css">

  <div id="background">
    <div id="playerDiv">
<script src="script.js"></script>


92 thoughts on “The square does not move JavaScript”

Leave a Comment