0

I'm trying to call a method from a "utils" file that contains functions, but I have this error :

Uncaught ReferenceError: utils is not defined

I checked my index.html, it does contains :

    <script src="js/app.js"></script>
    <script src="js/utils.js"></script>

So I tried to reverse those 2 lines :

    <script src="js/utils.js"></script>
    <script src="js/app.js"></script>

But then I get a new error :

app.js:7 Uncaught ReferenceError: Cannot access 'app' before initialization

Here is my app.js and util.js :

const app = {
    rowsNb: 4,
    columnsNb:6,

    rowPosition: utils.getRandomNumber(1, app.rowsNb),
    columnPosition: utils.getRandomNumber(0, app.columnsNb - 1),

    init: () => {
        console.log('init');
        app.drawBoard();

        document.addEventListener('keydown', app.handleKeydown);
        document.getElementById('launchScript').addEventListener('click', app.handleLaunchScriptButton)
    }, 
    
    ...

   document.addEventListener('DOMContentLoaded', app.init);
const utils = {
    getRandomNumber: (min, max) => {
        let randomNumber =  Math.random() * (max - min) + min;
        return Math.round(randomNumber);
    }
}
Tristan
  • 1
  • 3

0 Answers0