- Clone the repository
- Add questions to the
questions.jsonfile - Run
node server.jsto start the server - Open
localhost:3000in your browser
Note: the legacy way of doing it was python server.py but python does not support websockets out of the box where Node.js does. So server.py is deprecated in favor of server.js.
Questions are stored in the questions.json file. The questions are stored in an array of objects. Each object represents a question and has the following properties:
name: The name of the questiontitle: The title of the questiontype: The type of question
See the SurveyJS documentation for the different question types and their properties. There are a lot of them, so I won't go into detail here.
As the user interacts with the quiz, the answers are stored in the answers.json file. The answers are stored in an array of objects. Each object represents a question and has the following properties:
name: The name of the questionvalue: The value of the questioncorrectAnswer: The correct answer to the questionisCorrect: Whether the answer is correct
To run the solution, run python format_answers.py. This will read the questions.json and answers.json files and format the answers into a human readable format.
First, you must use the node version of the server (server.js). It exposes a websocket and a /validate endpoint you can POST to. It will request the HTML to annotate the UX.
If you want the Web UX to display the correct/incorrect state to the user, you can make a request to the quiz server:
curl -X POST localhost:3000/validate &> /dev/null
The 2 main dependencies required for this project are python and node. Both can be gotten in the python base images, since every base image contains node as well. A few files need to be created to make the solution work standalone.
An example can be found here
if [ -f questions.json ]; then
wget https://github.com/CodeSignal/learn_quiz-task/releases/latest/download/dist.tar.gz
mkdir -p learn_quiz
cd learn_quiz
tar xzf ../dist.tar.gz
cp ../questions.json questions.json
npm start
exit 0
fi#!/bin/bash
# force all clients (just the one for the preview window) to update
# their display and show the correctness of the answers
curl -X POST localhost:3000/validate &> /dev/null
# process the answers given to assess if the learner correctly
# completed the quiz
python3 format_answers.py
exit 0This is the format used by Survey.js and an example is in questions.json. But we sometimes want to use Markdown to define the questions (example: questions.md). You can convert the Markdown to JSON if you prefer. In that case, you can convert it to JSON:
node convert-questions-md-to-json.js -i questions.md -o questions.jsonThe expected setup in the view settings (present either on the course level or on the task level):
- Task Preview: "Full Screen"
- Task Preview URL Header: "Hidden"
- Refresh Preview on Run: "Disabled"
- Preview Loading Message: "Custom"
- Custom Preview Loading Message: "Starting Quiz..."
- Reset Session Button Location: "Preview"
- Preview Position: "top:10px; right:10px"
Are you sure you didn't store your particular questions in a path different than the one used in the setup.sh file?
Ensure you are using the latest release of this repository. While the script assume version 0.7, it could very well be that a bug was fixed somewhere down the line and a newer release fixes the issues.