Home > Net >  How to get determine a variable from another variable
How to get determine a variable from another variable

Time:07-17

I have a trivia game in discord.js and need to be able to fetch questions and answers from a json file from a random number since i have multiple lists of questions that it would pick based off like 1.json, 2.json based of a random number gen but every time i try to fetch a question (trivia.QX) it says that trivia is not defined when the code calls for it if the number is 1 it goes for const trivia = require(./game/trivia/1.json) same with 2 and any others i have no clue why it wont work. (sorry about me forgetting to add .'s)

CodePudding user response:

require takes a string input, meaning the file path needs to be in quotes.

const trivia = require('./game/trivia/1.json');
  • Related