5. Core JS Functions
HTML to Load JavaScript Libraries
In the code below the script tags load libraries that make coding your game much easier. To all the people that work on free and open source projects, thank you!! You are adding the papaparse, jquery, p5.js, and the iDEW trivia libraries here.
Add the code below to the bottom of your HTML body. (Place just before the tag for your custom JS code<script src="script.js"></script>
if needed.
Core JavaScript Functions of Trivia Game
We are assuming you don't want your trivia game to be a static page and make people scroll down the screen just to see a trivia question. That's where JavaScript comes in to give you control of how the trivia game interacts and displays content when and where you want.
setup( ) This function runs once when the visitor first comes to the page. For example, we will load the question database here.
displayWelcome( ) , displayQuestion( ) , displayThankyou( ) These functions control what is displayed for each of our screens.
onClickedAnswer( ) , onClickedStart( ) These functions control what happens when buttons are clicked.
Copy the JavaScript below and paste it in a new script.js file. Nothing new will happen just yet. That's next.