Skip to content

Instantly share code, notes, and snippets.

View StevenWuTG's full-sized avatar

Steven Wu StevenWuTG

  • New York
View GitHub Profile
/first you need to find a parent element node
const parent2 = document.querySelector("#parent-2")
const child1Ofparent2 = parent2.childNodes[0]
//this will return the child-3 node which is at the first index of parent2
const child2Ofparent2 = parent2.childNodes[1]
//this will return the child-4 node which is at the second index of parent2
const ballBoundaries = () => {
// Bounce off Left Wall
if (ballX < 0 && speedX < 0) {
speedX = -speedX
}
// Bounce off Right Wall
if (ballX > width && speedX > 0) {
speedX = -speedX
}
// Bounce off player paddle (bottom)