PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, July 24, 2022

[FIXED] How to get determine a variable from another variable

 July 24, 2022     constants, discord.js, javascript, json, node.js     No comments   

Issue

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)


Solution

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

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


Answered By - Ryan Pattillo
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing