> ## Documentation Index
> Fetch the complete documentation index at: https://docs.timeback.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Question loop

> Fetch questions and submit answers during a lesson session

Once you have a `LessonSession` from [`lessons.start()`](/beta/build-on-timeback/sdk/managed-lessons/lesson-discovery#start-a-lesson), the question loop is how your app drives the lesson forward. Call `session.next()` to get a question, render it, then call `session.submit()` with the student's answer.

## The basic loop

```typescript theme={null}
let question = await session.next()

while (question) {
	// Render the question, collect an answer from the student
	const answer = await renderQuestion(question)

	const result = await session.submit({
		question: question.id,
		response: answer,
	})

	// result.score, result.correct, result.complete are available

	question = await session.next()
}

// No more questions -- complete the lesson
const completion = await session.complete()
```

## Fetch a question

`session.next()` returns the next `LessonQuestion`, or `null` when there are no more questions:

```typescript theme={null}
const question = await session.next()

if (!question) {
	// Lesson is complete, call session.complete()
}
```

Each question includes an `id` and `content.rawXml` with [QTI](https://www.imsglobal.org/question/index.html) XML. Your app is responsible for parsing and rendering this XML.

<Info>
  See the [reference](/beta/build-on-timeback/sdk/managed-lessons/reference#lessonquestion) for the full type.
</Info>

<Warning>
  QTI XML parsing utilities are coming soon to the SDK. In the meantime, you'll need to parse the
  XML yourself to extract prompts, choices, and correct responses.
</Warning>

## Submit an answer

After the student answers, submit their response:

```typescript theme={null}
const result = await session.submit({
	question: question.id,
	response: selectedAnswer,
})
```

The result tells you whether the answer was `correct`, the updated `score`, and whether the lesson is now `complete`. After each submission, the session's `score` and `finalized` properties update automatically.

<Info>
  See the [reference](/beta/build-on-timeback/sdk/managed-lessons/reference#lessonsubmitresult) for full parameter and return type documentation.
</Info>

```typescript theme={null}
const result = await session.submit({ question: question.id, response: 'A' })
console.log(result.correct) // Whether the answer was correct
console.log(session.score) // Updated cumulative score
console.log(session.finalized) // true if the lesson auto-completed
```

## Adaptive vs linear delivery

The SDK handles two delivery modes transparently. Your code uses the same `next()` / `submit()` loop regardless of mode.

<Note>
  You do not need to detect which mode is active. The `LessonSession` handles it based on the
  `lessonType` set during
  [`lessons.start()`](/beta/build-on-timeback/sdk/managed-lessons/lesson-discovery#start-a-lesson).
</Note>

### Adaptive (`powerpath-100`)

Each `next()` call hits the server, which asks PowerPath for the next question based on the student's performance so far. Questions are served one at a time, and difficulty adapts.

### Linear (`quiz`, `test-out`, etc.)

On the first `next()` call, the SDK fetches **all** questions at once and buffers them locally. Subsequent `next()` calls return from the local buffer without a network round trip. Already-answered questions are skipped automatically.

## Track progress during the loop

The [session properties](/beta/build-on-timeback/sdk/managed-lessons/reference#lesson-session) update in real time as the student progresses. Use `session.score`, `session.finalized`, and `session.lessonType` to render progress indicators, score displays, or early-completion UI.

## Next steps

<CardGroup cols={2}>
  <Card title="Completion" icon="flag-checkered" href="/beta/build-on-timeback/sdk/managed-lessons/completion">
    Finalize scoring and interpret results
  </Card>

  <Card title="Reference" icon="code" href="/beta/build-on-timeback/sdk/managed-lessons/reference">
    Parameters, properties, methods, and return types
  </Card>
</CardGroup>
