> For the complete documentation index, see [llms.txt](https://www.xapijs.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.xapijs.dev/cmi5-profile-library/cmi5-defined-statements.md).

# "cmi5 defined" Statement methods

## initialize

Initializes the session, must be called before performing other methods.

### **Example**

```typescript
import Cmi5 from "@xapi/cmi5";

const cmi5 = new Cmi5();

cmi5.initialize();
```

### **Parameters**

| Parameter    | Type   | Required | Description                                                                                                                 |
| ------------ | ------ | -------- | --------------------------------------------------------------------------------------------------------------------------- |
| sessionState | Object | false    | An auth token and initialized date from a previous initialisation. Useful for persisting sessions across browser refreshes. |

### **Returns**

This returns a `Promise` containing an array with the resulting statementId if successful, or `undefined` if a `sessionState` is provided.

## complete

Completes the AU. Required for satisfaction if `LaunchData.moveOn` is equal to `Completed`, `CompletedAndPassed` or `CompletedOrPassed`.

### **Example**

```typescript
import Cmi5 from "@xapi/cmi5";

const cmi5 = new Cmi5();

// initialize etc

cmi5.complete();
```

### **Parameters**

| Parameter | Type                                                                                                      | Required | Description                    |
| --------- | --------------------------------------------------------------------------------------------------------- | -------- | ------------------------------ |
| options   | [SendStatementOptions](https://github.com/xapijs/cmi5/blob/master/src/interfaces/SendStatementOptions.ts) | false    | The additional options object. |

### Returns

This returns a `Promise` containing an array with the resulting statementId if successful.

## pass

Passes the AU. Required for satisfaction if `LaunchData.moveOn` is equal to `Passed`, `CompletedAndPassed` or `CompletedOrPassed`.

### **Examples**

#### **Example 1: Pass**

```typescript
import Cmi5 from "@xapi/cmi5";

const cmi5 = new Cmi5();

// initialize etc

cmi5.pass();
```

#### **Example 2: Pass with score**

```typescript
import Cmi5 from "@xapi/cmi5";
import { ResultScore } from "@xapi/xapi";

const cmi5 = new Cmi5();

// initialize etc

const score: ResultScore = {
  scaled: 0.95,
  raw: 95
  min: 0
  max: 100
}

cmi5.pass(score);
```

#### **Example 3: Pass with score and objective**

```typescript
import Cmi5 from "@xapi/cmi5";
import { ResultScore, ObjectiveActivity } from "@xapi/xapi";

const cmi5 = new Cmi5();

// initialize etc

const score: ResultScore = {
  scaled: 0.95,
  raw: 95
  min: 0
  max: 100
}

const objective: ObjectiveActivity = {
  objectType: "Activity",
  id: "https://github.com/xapijs/cmi5/objectives/test",
  definition: {
    type: "http://adlnet.gov/expapi/activities/objective",
    name: {
      "en-US": "Example Objective"
    },
    description: {
      "en-US": "An example objective."
    }
  }
}

cmi5.pass(score, objective);
```

### **Parameters**

| Parameter          | Type                                                                                                                                                                                                                                     | Required | Description                                                             |
| ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | ----------------------------------------------------------------------- |
| score              | [ResultScore](https://github.com/xapijs/xapi/blob/master/src/XAPI/interfaces/Statement/Result.ts)                                                                                                                                        | false    | The score achieved by the learner.                                      |
| objectiveOrOptions | [ObjectiveActivity](https://github.com/xapijs/xapi/blob/master/src/XAPI/interfaces/Statement/Activity/ObjectiveActivity.ts) or [SendStatementOptions](https://github.com/xapijs/cmi5/blob/master/src/interfaces/SendStatementOptions.ts) | false    | The objective achieved by the learner or the additional options object. |

Note: If using score and/or objective parameters, types for these are in `@xapi/xapi` and must be installed as a dev dependency `npm i --save-dev @xapi/xapi`.

### **Returns**

This returns a `Promise` containing an array with the resulting statementId if successful.

## fail

Fails the AU. Required to mark the AU as Failed if `LaunchData.moveOn` is equal to `Passed`, `CompletedAndPassed` or `CompletedOrPassed`.

### **Examples**

#### **Example 1: Fail**

```typescript
import Cmi5 from "@xapi/cmi5";

const cmi5 = new Cmi5();

// initialize etc

cmi5.fail();
```

#### **Example 2: Fail with score**

```typescript
import Cmi5 from "@xapi/cmi5";
import { ResultScore } from "@xapi/xapi";

const cmi5 = new Cmi5();

// initialize etc

const score: ResultScore = {
  scaled: 0.25,
  raw: 25
  min: 0
  max: 100
}

cmi5.fail(score);
```

### **Parameters**

| Parameter | Type                                                                                                      | Required | Description                        |
| --------- | --------------------------------------------------------------------------------------------------------- | -------- | ---------------------------------- |
| score     | [ResultScore](https://github.com/xapijs/xapi/blob/master/src/XAPI/interfaces/Statement/Result.ts)         | false    | The score achieved by the learner. |
| options   | [SendStatementOptions](https://github.com/xapijs/cmi5/blob/master/src/interfaces/SendStatementOptions.ts) | false    | The additional options object.     |

Note: If using the score parameter, types for this are in `@xapi/xapi` and must be installed as a dev dependency `npm i --save-dev @xapi/xapi`.

### **Returns**

This returns a `Promise` containing an array with the resulting statementId if successful.

## terminate

Terminates the session, must be the last method called before closing the window.

### **Example**

```typescript
import Cmi5 from "@xapi/cmi5";

const cmi5 = new Cmi5();

// initialize etc

cmi5.terminate();
```

### **Returns**

This returns a `Promise` containing an array with the resulting statementId if successful.
