Tug Of War Checking #151598
Replies: 2 comments 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.
-
💬 Your Product Feedback Has Been Submitted 🎉 Thank you for taking the time to share your insights with us! Your feedback is invaluable as we build a better GitHub experience for all our users. Here's what you can expect moving forward ⏩
Where to look to see what's shipping 👀
What you can do in the meantime 💻
As a member of the GitHub community, your participation is essential. While we can't promise that every suggestion will be implemented, we want to emphasize that your feedback is instrumental in guiding our decisions and priorities. Thank you once again for your contribution to making GitHub even better! We're grateful for your ongoing support and collaboration in shaping the future of our platform. ⭐ |
Beta Was this translation helpful? Give feedback.
-
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