Cannot access ‘isColliding’ before initialization/ divs colliding

I’m trying to make an egg catching game and found some code snippets online and wanted them to work together so the points go up by one when two divs are colliding. I am getting this error Cannot access ‘isColliding’ before initialization. Also I don’t know if the div collision works since I can’t test it because of the error, thanks in advance for any help!


let points = $('#points');
let countpoints = 0;
let overlap = isColliding("#basket", "#egg6");

if (overlap) {
    function EggHitsBasket() {
        points.text("points:" + countpoints);

let isColliding = function (div1, div2) {

    let d1Offset = div1.offset();
    let d1Height = div1.outerHeight(true);
    let d1Width = div1.outerWidth(true);
    let d1Top = + d1Height;
    let d1Left = d1Offset.left + d1Width;

    let d2Offset = div2.offset();
    let d2Height = div2.outerHeight(true);
    let d2Width = div2.outerWidth(true);
    let d2Top = + d2Height;
    let d2Left = d2Offset.left + d2Width;

    return !(d1Top < || > d2Top || d1Left < d2Offset.left || d1Offset.left > d2Left);


you’re calling isColliding before it’s been defined, it’s the same that would happen in the following code snippet:

let x = y * 2
let y = 42

you need to either declare isColliding before you call it. Or use of a function declaration

function isColiiding(div1, div2) { ... }

rather than a function expression

let isColliding = function (div1, div2) { ... }