NPR News Quiz

It's a news quiz

Updated a year ago to v1.0.105 by Holly J Morris

This section documents API usage specific to this template, so for an introduction we suggest you refer to the generic API documentation instead.

template: @eightchbomb/npr-news-quiz

version: 1

Template data

There are three different formats in which you can supply data to this template. The most convenient for you to use likely depends on the source of your data, as described below.

1. Array of arrays, and a bindings object

You can supply arrays of arrays to opts.data, which might look like:

{
    data: {
        quiz: [
            [ "QuizColumn1Value1", "QuizColumn2Value1",
            [ "QuizColumn1Value2", "QuizColumn2Value2",
            [ "QuizColumn1Value3", "QuizColumn2Value3",
            ...
        ],
        scoring: [
            [ "ScoringColumn1Value1", "ScoringColumn2Value1",
            [ "ScoringColumn1Value2", "ScoringColumn2Value2",
            [ "ScoringColumn1Value3", "ScoringColumn2Value3",
            ...
        ]
    }
}

where each array of arrays represents the rows in a data sheet.

To tell the API how the values from each column should be associated with the keys that the template is expecting, you must also supply an object attached to opts.bindings. (The meanings of the keys in the bindings object are documented below.) The minimal bindings you can supply for this template are as shown in this example:

{
    template: "@eightchbomb/npr-news-quiz",
    version: "1",
    bindings: {
        quiz: {
            question: 0, // index of a column in your data
            answer1: 1, // index of a column in your data
            answer2: 2, // index of a column in your data
            answer3: 3, // index of a column in your data
            answer4: 4, // index of a column in your data
            correct: 5, // index of a column in your data
            correct_long_answer: 6, // index of a column in your data
            answer_feedback_wrong: 7, // index of a column in your data
            answer_feedback_correct: 8, // index of a column in your data
            image_question: 9, // index of a column in your data
            image_question_alt: 10, // index of a column in your data
            image_question_credit: 11, // index of a column in your data
            image_answer: 12, // index of a column in your data
            image_answer_alt: 13, // index of a column in your data
            image_answer_credit: 14, // index of a column in your data
        },
        scoring: {
            final_score: 0, // index of a column in your data
            final_feedback: 1, // index of a column in your data
        }
    },
    data: {
        quiz: [
            [ "QuizColumn1Value1", "QuizColumn2Value1",
            [ "QuizColumn1Value2", "QuizColumn2Value2",
            [ "QuizColumn1Value3", "QuizColumn2Value3",
            ...
        ],
        scoring: [
            [ "ScoringColumn1Value1", "ScoringColumn2Value1",
            [ "ScoringColumn1Value2", "ScoringColumn2Value2",
            [ "ScoringColumn1Value3", "ScoringColumn2Value3",
            ...
        ]
    }
}

All possible bindings that you can supply are shown in this example:

{
    template: "@eightchbomb/npr-news-quiz",
    version: "1",
    bindings: {
        quiz: {
            question: 0, // index of a column in your data
            answer1: 1, // index of a column in your data
            answer2: 2, // index of a column in your data
            answer3: 3, // index of a column in your data
            answer4: 4, // index of a column in your data
            correct: 5, // index of a column in your data
            correct_long_answer: 6, // index of a column in your data
            answer_feedback_wrong: 7, // index of a column in your data
            answer_feedback_correct: 8, // index of a column in your data
            image_question: 9, // index of a column in your data
            image_question_alt: 10, // index of a column in your data
            image_question_credit: 11, // index of a column in your data
            image_answer: 12, // index of a column in your data
            image_answer_alt: 13, // index of a column in your data
            image_answer_credit: 14, // index of a column in your data
        },
        scoring: {
            final_score: 0, // index of a column in your data
            final_feedback: 1, // index of a column in your data
        }
    },
    data: {
        quiz: [
            [ "QuizColumn1Value1", "QuizColumn2Value1",
            [ "QuizColumn1Value2", "QuizColumn2Value2",
            [ "QuizColumn1Value3", "QuizColumn2Value3",
            ...
        ],
        scoring: [
            [ "ScoringColumn1Value1", "ScoringColumn2Value1",
            [ "ScoringColumn1Value2", "ScoringColumn2Value2",
            [ "ScoringColumn1Value3", "ScoringColumn2Value3",
            ...
        ]
    }
}

2. Array of objects with arbitrary keys, and a bindings object

This format is most likely useful when you have data from an external source, such as CSV data loaded from d3-dsv. You should supply this attached to the opts.data, which might look like:

{
        quiz: [
            { "QuizHeader1": ..., "QuizHeader2": ..., ... },
            { "QuizHeader1": ..., "QuizHeader2": ..., ... },
            { "QuizHeader1": ..., "QuizHeader2": ..., ... },
            ...
        ],
        scoring: [
            { "ScoringHeader1": ..., "ScoringHeader2": ..., ... },
            { "ScoringHeader1": ..., "ScoringHeader2": ..., ... },
            { "ScoringHeader1": ..., "ScoringHeader2": ..., ... },
            ...
        ]
    }

... but with the keys being the column headers from your source data instead. You must also supply an object attached to opts.bindings. The minimal bindings you can supply for this template are as shown in this example:

{
    template: "@eightchbomb/npr-news-quiz",
    version: "1",
    bindings: {
        quiz: {
            question: "QuizHeader1",
            answer1: "QuizHeader2",
            answer2: "QuizHeader3",
            answer3: "QuizHeader4",
            answer4: "QuizHeader5",
            correct: "QuizHeader6",
            correct_long_answer: "QuizHeader7",
            answer_feedback_wrong: "QuizHeader8",
            answer_feedback_correct: "QuizHeader9",
            image_question: "QuizHeader10",
            image_question_alt: "QuizHeader11",
            image_question_credit: "QuizHeader12",
            image_answer: "QuizHeader13",
            image_answer_alt: "QuizHeader14",
            image_answer_credit: "QuizHeader15",
        },
        scoring: {
            final_score: "ScoringHeader1",
            final_feedback: "ScoringHeader2",
        }
    },
    data: {
        quiz: [
            { "QuizHeader1": ..., "QuizHeader2": ..., ... },
            { "QuizHeader1": ..., "QuizHeader2": ..., ... },
            { "QuizHeader1": ..., "QuizHeader2": ..., ... },
            ...
        ],
        scoring: [
            { "ScoringHeader1": ..., "ScoringHeader2": ..., ... },
            { "ScoringHeader1": ..., "ScoringHeader2": ..., ... },
            { "ScoringHeader1": ..., "ScoringHeader2": ..., ... },
            ...
        ]
    }
}

All possible bindings that you can supply are shown in this example:

{
    template: "@eightchbomb/npr-news-quiz",
    version: "1",
    bindings: {
        quiz: {
            question: "QuizHeader1",
            answer1: "QuizHeader2",
            answer2: "QuizHeader3",
            answer3: "QuizHeader4",
            answer4: "QuizHeader5",
            correct: "QuizHeader6",
            correct_long_answer: "QuizHeader7",
            answer_feedback_wrong: "QuizHeader8",
            answer_feedback_correct: "QuizHeader9",
            image_question: "QuizHeader10",
            image_question_alt: "QuizHeader11",
            image_question_credit: "QuizHeader12",
            image_answer: "QuizHeader13",
            image_answer_alt: "QuizHeader14",
            image_answer_credit: "QuizHeader15",
        },
        scoring: {
            final_score: "ScoringHeader1",
            final_feedback: "ScoringHeader2",
        }
    },
    data: {
        quiz: [
            { "QuizHeader1": ..., "QuizHeader2": ..., ... },
            { "QuizHeader1": ..., "QuizHeader2": ..., ... },
            { "QuizHeader1": ..., "QuizHeader2": ..., ... },
            ...
        ],
        scoring: [
            { "ScoringHeader1": ..., "ScoringHeader2": ..., ... },
            { "ScoringHeader1": ..., "ScoringHeader2": ..., ... },
            { "ScoringHeader1": ..., "ScoringHeader2": ..., ... },
            ...
        ]
    }
}

(As before, the keys containing "Header" would be replaced by column names from your data source.)

3. Array of objects with template-defined keys

There is an alternative format you can use, which is likely to be easier to use if your data is not from a spreadsheet source. With this alternative format you supply your data to the template as an array of objects, attached to opts.data, where the keys must be those used by the template, as documented below. In this case there is no need to supply a bindings object, since the key names are already those expected by the template. The required properties in the data object are as follows (scroll down for a description of what each property is):

{
    template: "@eightchbomb/npr-news-quiz",
    version: "1",
    data: {
    quiz: [
        {
            question: ...,
            answer1: ...,
            answer2: ...,
            answer3: ...,
            answer4: ...,
            correct: ...,
            correct_long_answer: ...,
            answer_feedback_wrong: ...,
            answer_feedback_correct: ...,
            image_question: ...,
            image_question_alt: ...,
            image_question_credit: ...,
            image_answer: ...,
            image_answer_alt: ...,
            image_answer_credit: ...
        },
        ...
    ],
    scoring: [
        {
            final_score: ...,
            final_feedback: ...
        },
        ...
    ]
},
    ...
}

And the full list of all possible properties is as follows:

{
    template: "@eightchbomb/npr-news-quiz",
    version: "1",
    data: {
    quiz: [
        {
            question: ...,
            answer1: ...,
            answer2: ...,
            answer3: ...,
            answer4: ...,
            correct: ...,
            correct_long_answer: ...,
            answer_feedback_wrong: ...,
            answer_feedback_correct: ...,
            image_question: ...,
            image_question_alt: ...,
            image_question_credit: ...,
            image_answer: ...,
            image_answer_alt: ...,
            image_answer_credit: ...
        },
        ...
    ],
    scoring: [
        {
            final_score: ...,
            final_feedback: ...
        },
        ...
    ]
},
    ...
}

Meanings of the template data keys:

  • quiz.question: question
  • quiz.answer1: answer1
  • quiz.answer2: answer2
  • quiz.answer3: answer3
  • quiz.answer4: answer4
  • quiz.correct: correct
  • quiz.correct_long_answer: correct_long_answer
  • quiz.answer_feedback_wrong: answer_feedback_wrong
  • quiz.answer_feedback_correct: answer_feedback_correct
  • quiz.image_question: image_question
  • quiz.image_question_alt: image_question_alt
  • quiz.image_question_credit: image_question_credit
  • quiz.image_answer: image_answer
  • quiz.image_answer_alt: image_answer_alt
  • quiz.image_answer_credit: image_answer_credit
  • scoring.final_score: final_score
  • scoring.final_feedback: final_feedback

Template settings

Options for opts.state.

Nothing to see here