简体   繁体   中英

How to get determine a variable from another variable

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)

require接受string输入,这意味着文件路径需要用引号引起来。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM