Because this question is lodged in my head, a little script to run the game:
```bash
#!/usr/bin/env bash
main() {
local -a questions
mapfile -t questions < <(
get_quiz |
jq -r '.results[] | [.question] + [.correct_answer] + .incorrect_answers | @sh'
)
for i in "${!questions[@]}"; do
local -a q="( ${questions[i]} )"
question $((i+1)) "${q[@]}"
done
}
question() {
local num=$1 question=$2 correct=$3
local -a answers=("${@:3}")
# shuffle the answers
mapfile -t answers < <(printf "%s\n" "${answers[@]}" | sort -R)
echo
echo "Question #$num"
PS3="${question//"/\'} "
select answer in "${answers[@]}"; do
if [[ $answer == "$correct" ]]; then
echo "Correct"
break
fi
echo "Incorrect"
done
}
get_quiz() {
# this is where you'd do your curl call, but
# for now, the sample data is printed.
cat << 'JSON'
{
"response_code": 0,
"results": [
{
"category": "Entertainment: Television",
"type": "multiple",
"difficulty": "easy",
"question": "Which company has exclusive rights to air episodes of the "The Grand Tour"?",
"correct_answer": "Amazon",
"incorrect_answers": [
"Netflix",
"BBC",
"CCTV"
]
},
{
"category": "Celebrities",
"type": "multiple",
"difficulty": "medium",
"question": "How much weight did Chris Pratt lose for his role as Star-Lord in "Guardians of the Galaxy"?",
"correct_answer": "60 lbs",
"incorrect_answers": [
"30 lbs",
"50 lbs",
"70 lbs"
]
},
{
"category": "Animals",
"type": "boolean",
"difficulty": "easy",
"question": "The Killer Whale is considered a type of dolphin.",
"correct_answer": "True",
"incorrect_answers": [
"False"
]
}
]
}
JSON
}
main
```