The data model is very important to get right: this is how we'll store our questions, the answers to those questions, and which answer is the correct answer for each of the questions. We'll also define how we should interact with the model, that is, how do we get a question, ask it if the answer is correct, and so forth.
Let's get out our pencil and paper again, or if you'd prefer, a diagramming tool that you're comfortable with. What we're really trying to do in this step is to come up with the properties the model needs in order to store the questions, and the interactions it will need in order to properly do everything we're asking of it.
We'll essentially have two data models: a single question, and a collection of questions. Let's start with what the question model should do:
We can indicate this by creating a simple diagram as follows:
Our collection of questions should:
The diagram covering these points would look like the following screenshot:
Having both of the models defined, let's come up with the questions we're going to ask, as well as the answers that will go along with them (for the full list of questions, see chapter1/www/models/quizQuestions.js
in the download for this book):
# |
English |
Spanish |
---|---|---|
|
What is the color of the Sun? |
¿Cuál es el color del Sol? |
Green |
Verde | |
White |
Blanco | |
Yellow (correct) |
Amarillo (correct) | |
|
What is the name of the fourth planet? |
¿Cuál es el nombre del cuarto planeta? |
Mars (correct) |
Marzo (correct) | |
Venus |
Venus | |
Mercury |
Mercurio |
With the design of our model complete, and the questions we're going to ask, this task is complete. Next we'll write the code to implement the model.
18.222.210.166