Trivia JS Library Reference
Trivia Methods
trivia.loadGoogleSheet(link)
Used to load a question bank from a Google Sheet.
trivia.getCategories()
Returns all category names in an array.
trivia.getUnfinishedCategories()
Returns category names of the categories having unanswered questions. Returns as an array.
trivia.gotoNextQuestion()
Advances the trivia game to the next question.
trivia.insertCategoryInfo()
This function places a button for each category into the HTML.
trivia.insertQuestionInfo()
This function puts the current question and answers taken from your database into the HTML to be displayed.
trivia.shuffleAnswers()
This function shuffles the multiple choice answers so that the correct answer does not always show at the top.
trivia.startClickListeners()
This function simply starts the event listeners for different types of player clicks.
Trivia Objects and Attributes
trivia.questions
This is an array of the trivia question objects.
trivia.currentQuestion
This is the current trivia question object which contains key/value pairs defined by the question database. For example, trivia.currentQuestion.category will contain the category label for the current question if it is available. The standard question object keys are below, but can be extended as needed.
category
question
correctAnswer
incorrectAnswer1
incorrectAnswer2
incorrectAnswer3
trivia.questionIndex
This provides the current question's index in the questions array.
trivia.totalQuestions
The provides the total questions in the game.
trivia.totalCorrect
This provides how many correct answers the player has at the moment.
trivia.totalAnswered
This provides how many questions have been answered by the player at that moment.
trivia.state
This provides the state of the game. Possible states -- 'welcome', 'question', 'correct', 'incorrect', and 'thankyou'.
Raw Library JavaScript
Quick Start for Code Template
Copy the HTML/CSS/JavaScript below to get started immediately.