Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ASPhillips8
Copy link

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.

Copy link

@stephenmckeon stephenmckeon left a 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
Comment on lines 5 to 14
function moveDodgerLeft() {
if (left > 0) {
dodger.style.left = `${left - 1}px`;
}
}

function moveDodgerRight () {
if (left < 360)
dodger.style.left = `${left + 1}px`;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Comment on lines 16 to 22
document.addEventListener("keydown", function (e) {
if (e.key === "ArrowLeft") {
moveDodgerLeft();
} else if (e.key === "Arrow Right") {
moveDodgerRight
}
});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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();
}
});

Copy link

@stephenmckeon stephenmckeon left a 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants