Guide 2.9: Developer Guide

Fetching Answers & Solutions

Unlike some APIs that force you to make a separate request to check if a user's answer is correct, SdashAPI optimizes for speed by including the correct answer and the full explanation directly inside the question payload.

The Answer Key

2.9.1

Look closely at the question response object. You will see an answer property. This string corresponds exactly to the key in the option object.

{
  "question": "Which gas is used by plants during photosynthesis?",
  "option": {
    "a": "Oxygen",
    "b": "Carbon dioxide", // <-- The correct text
    "c": "Nitrogen",
    "d": "Hydrogen"
  },
  "answer": "b" // <-- The correct key
}

Evaluating User Input

2.9.2

When building a quiz UI, your radio buttons should use the option keys (a, b, c, d) as their HTML value attributes. When the user clicks "Submit", you simply compare their selected value to the API's answer string.

// JavaScript Example
const userSelection = document.querySelector('input[name="q1"]:checked').value;
const correctAnswer = questionData.answer;

if (userSelection === correctAnswer) {
  showSuccessUI();
} else {
  showFailureUI();
}

Security & Cheating

2.9.3

Because the correct answer is sent to the browser immediately, tech-savvy students can inspect the network tab and find the answer. If you are building a strict, high-stakes testing environment (like an actual entrance exam), you must not send the raw SdashAPI response to the frontend. Instead, proxy the request through your own backend, strip out the answer property, send the stripped question to the frontend, and grade the exam on your server when the student finishes.

The Solution Field

2.9.4

SdashAPI provides a solution field containing step-by-step reasoning. This field is incredibly valuable for study apps. However, note that some questions (especially simple recall questions like "What is the capital of Nigeria?") might have a null solution if an explanation is deemed unnecessary. Always check if the solution is null before attempting to render it in your UI.

Want specific subjects?

Next, we will look at how to filter questions to build targeted quizzes.

Next Guide: Filtering by Subject →
Avatar

How can we help?

We reply immediately

Hello! 👋 How can we help you today?