Staircase class
How to add a Staircase to your online study.

1. Add the Staircase JavaScript file to your code

Either

Add import "staircase.js" to your JavaScript code

Or

Add <script src="staircase.js"></script> to your HTML code

2. Create the Staircase

Create a new variable for the Staircase. In this example, it is called myStaircase.

let myStaircase

Then, initialise the Staircase.

myStaircase = new Staircase()

The default parameters are:

myStaircase = new Staircase(
  min = 1, max = 10, start = min,
  up = {increment: +1, repeatsToMove: 1},
  down = {increment: -1, repeatsToMove: 1}
)
Parameter Type Default
min number 1 Lowest level on the staircase
max number 10 Highest level on the staircase
start number min Starting position on the staircase
up.increment int +1 Number of steps and direction when moving "up"
up.repeatsToMove int 1 Number of consecutive moveUp() before moving "up"
down.increment int -1 Number of steps and direction when moving "down"
down.repeatsToMove int 1 Number of consecutive moveDown() before moving "down"

3. Using the Staircase

Call myStaircase.moveUp() to attempt to move up the staircase. If the number of consecutive repeats of moveUp() equals up.repeatsToMove, the move will succeed. Likewise, use myStaircase.moveDown() to attempt a move downwards.

Example
if (response == correctAnswer) {
  myStaircase.moveUp()
} else {
  myStaircase.moveDown()
}

myStaircase contains various properties that can be accessed and modified.

Example
if (myStaircase.reversals >= 5) {
  // do something
}
Property Type Default starting value
.minimum number 1 Lowest level on the staircase
.maximum number 10 Highest level on the staircase
.up object {increment: +1, repeatsToMove: 1} Parameters for moving "up" the staircase
.down object {increment: -1, repeatsToMove: 1} Parameters for moving "down" the staircase
.currentStep number start Current step on the staircase
.repeats object {up: 0, down: 0} Current number of consecutive repeats
.reversals number 0 Number of reversals
.lastStepDirection string null Direction of the last successful step change: up, down
.history number[] empty array History of all steps on the staircase.
The position is recorded even if the move did not occur, i.e. repeatsToMove not fulfilled