diff --git a/index.js b/index.js index 877a3aa08..0d3281c6d 100644 --- a/index.js +++ b/index.js @@ -1 +1,32 @@ -// Your code here +function moveDodgerLeft() { + const leftNumbers = dodger.style.left.replace("px", ""); + const left = parseInt(leftNumbers, 10); + + if (left > 0) { + dodger.style.left = `${left - 1}px`; + } +} + +document.addEventListener("keydown", function (e) { + if (e.key === "ArrowLeft") { + moveDodgerLeft(); + } +}); + +function moveDodgerRight() { + const leftNumbers = dodger.style.left.replace("px", ""); + const left = parseInt(leftNumbers, 10); + + if (left < 360) { + dodger.style.left = `${left + 1}px`; + } +} + +document.addEventListener("keydown", function (e) { + if (e.key === "ArrowRight") { + moveDodgerRight(); + } +}); + + +