0

I am generating a random number inside a javascript file that I need to pass through to an .ejs file. Obivously I can't just reproduce it there because it is random.

I am working with these files: app.js, game.js and game.ejs. I need to use the variable in both game files.

This is the variable I need to be shared

var num = Math.floor(Math.random()*4)

I already tried passing the variable through my app.js to the game.ejs which worked. I can still not work with it in my game.js though.

Any help is appreciated

Philipp K
  • 193
  • 2
  • 18

1 Answers1

0

make this varibale global like

global.num = Math.floor(Math.random()*4)

now use it at any place inside your environment.

Global varibales must be handled with care as it pollutes

Saikat Hajra
  • 670
  • 3
  • 12