Tug Of War Checking #151598
Unanswered
Naksh-Rathore
asked this question in
Programming Help
Tug Of War Checking
#151598
Replies: 1 comment 1 reply
-
Hi, I'm currently seeing a technical error on line 3 (style element values are of function move(pixels, line) {
yOffset -= pixels;
rope.style.transform = `translateY(${yOffset}px)`;
const ropeRect = rope.getBoundingClientRect();
const lineRect = line.getBoundingClientRect();
if (pixels > 0 && ropeRect.bottom <= lineRect.top) {
yOffset = 0;
rope.style.transform = `translateY(${yOffset}px)`;
redScore++;
scoreDisplay.textContent = `${redScore} - ${blueScore}`;
if (redScore >= 3) {
playing = false;
yOffset = 0;
rope.style.transform = `translateY(${yOffset}px)`;
window.alert("Red Won!");
}
} else if (pixels < 0 && ropeRect.top >= lineRect.bottom) {
yOffset = 0;
rope.style.transform = `translateY(${yOffset}px)`;
blueScore++;
scoreDisplay.textContent = `${redScore} - ${blueScore}`;
if (blueScore >= 3) {
playing = false;
yOffset = 0;
rope.style.transform = `translateY(${yOffset}px)`;
window.alert("Blue Won!");
}
}
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Body
I am coding a Tug of War game in JS and my problem is that the conditionals for checking if the rope has crossed the line does not work. Here is my code:
function move(pixels, line) {
yOffset -= pixels;
rope.style.transform =
translateY(${yOffset}px)
;}
Guidelines
Beta Was this translation helpful? Give feedback.
All reactions