As a JavaScript beginner, I am looking for help in retrieving values from one function to another. Specifically, I would like to access the values of dinoRight, dinoLeft, and others in the cactus1move function.
const spawn = () => {
const dinoRight = document.getElementById('dino').getBoundingClientRect().left + document.getElementById('dino').getBoundingClientRect().width;
const dinoLeft = document.getElementById('dino').getBoundingClientRect().left;
const dinoHeight = document.getElementById('dino').getBoundingClientRect().height;
const cactusTop = document.getElementById('cactus').getBoundingClientRect().top;
const cactusWidth = document.getElementById('cactus').getBoundingClientRect().width;
const containerLeft = document.getElementById('Container').getBoundingClientRect().left;
cactus1move();
}
const cactus1move = setInterval(() => {
if (cactusTop <= dinoBottom && dinoRight >= cactusLeft && cactusRight >= dinoLeft) {
...
} else if (cactusLeft <= containerLeft + 10 && cactusLeft >= containerLeft){
...
} else {
...
}
}, 20)