-
Notifications
You must be signed in to change notification settings - Fork 8.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create Funcitons To Move Dodger #14
base: master
Are you sure you want to change the base?
Create Funcitons To Move Dodger #14
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AWESOME!!!
index.js
Outdated
function moveDodgerLeft() { | ||
if (left > 0) { | ||
dodger.style.left = `${left - 1}px`; | ||
} | ||
} | ||
|
||
function moveDodgerRight () { | ||
if (left < 360) | ||
dodger.style.left = `${left + 1}px`; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function moveDodgerLeft() { | |
if (left > 0) { | |
dodger.style.left = `${left - 1}px`; | |
} | |
} | |
function moveDodgerRight () { | |
if (left < 360) | |
dodger.style.left = `${left + 1}px`; | |
} | |
function moveDodgerLeft() { | |
if (left > 0) dodger.style.left = `${left - 1}px`; | |
} | |
function moveDodgerRight () { | |
if (left < 360) dodger.style.left = `${left + 1}px`; | |
} |
index.js
Outdated
document.addEventListener("keydown", function (e) { | ||
if (e.key === "ArrowLeft") { | ||
moveDodgerLeft(); | ||
} else if (e.key === "Arrow Right") { | ||
moveDodgerRight | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
document.addEventListener("keydown", function (e) { | |
if (e.key === "ArrowLeft") { | |
moveDodgerLeft(); | |
} else if (e.key === "Arrow Right") { | |
moveDodgerRight | |
} | |
}); | |
document.addEventListener("keydown", function (e) { | |
if (e.key === "ArrowLeft") { | |
moveDodgerLeft(); | |
} else if (e.key === "Arrow Right") { | |
moveDodgerRight(); | |
} | |
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job, NOW it should work. Looks like you figured it out why those variables needed to be inside the functions.
Create variable for dodger, left number and left value. Create function to move left. Create function to move right. Added event listener for left and right arrow.