var.test.is

getVar(id).test.is( value ) (since beta 0.3)

or getVar(id).test.is( function )

Tests the value of the Var element. You can pass a function which takes the element’s value as its argument and returns true or false.

Example:

[js highlight=”20,21″ try=”true”]newVar(“trialsLeft”, 3)
,
newText(“remain”, ” Number of remaining attempts: “)
.settings.after( newText(“trial”, “3”) )
,
newTextInput(“guess”, “Guess my name”)
.settings.after( getText(“remain”) )
.print()
.wait(
getTextInput(“guess”)
.test.text( /Jeremy/i )
.failure( // Wrong guess:
getVar(“trialsLeft”)
.set( v => v-1 ) // Decrease trialsLeft
,
getText(“trial”) // Update trial’s text with it
.settings.text( getVar(“trialsLeft”) )
,
getVar(“trialsLeft”) // Disable guess if 0 attempt left
.test.is(0)
.success( getTextInput(“guess”).settings.disable() )
)
)
[/js]