Feedback based on slider scale selection

PennController for IBEX Forums Support Feedback based on slider scale selection

Tagged: 

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #10372
    bixprag
    Participant

    Hello,

    I would like to provide participants with a response based on their selection on a slider scale (ranging from 0 to 99). With “scale.test.selected” I’m only able to test for one particular value, it seems. However, I would like to give participants feedback for a range of values, say, any value greater or smaller than 49. I’ve tried with some JavaScript code and also tried adopting some seemingly relevant code in the forum – with no success. Any hints on where to look for solutions would be most welcome.

    Here is a demonstration link with a minimal example that checks whether the slider has been clicked at all: https://farm.pcibex.net/r/DycvSK/

    -TS

    #10373
    Jeremy
    Keymaster

    Hello,

    You’ll need to use a Function element:

    newFunction( ()=>{const c=getScale("Conclusion")._element.choices; return c[c.length-1][1]>=49;}).test.is(true).success( newText("Yay!").print() )

    Jeremy

    #10391
    bixprag
    Participant

    Hello, Jeremy,

    thank you very much. It works perfectly!

    Best,
    TS

    #10395
    bixprag
    Participant

    Hello again,

    I’m afraid I’ve stumbled into another issue related to this question. While I’m now able to provide feedback for clicks on the left and right side of the slider, the procedure halts if I just click “Next” without clicking/selecting a value on the slider first. Ideally, I would like to provide a feedback in this case, too. I’ve tried using *getScale(“”).test.selected()…* conjoined to the function you provided in your earlier post by means of *.(and)*, but that doesn’t work. Also, a strategy I’ve been using just to check whether other scales have been clicked, doesn’t work here:

    newFunction("WaitSelect2", function(){ getScale("Gelungen")._element.jQueryElement.click(()=>this.scaleClicked=true) }).call()
    
    // ...
    
    newButton("Next")
            .center()
            .print()
            .wait(newFunction(function(){return this.scaleClicked;}).test.is(true).failure() // ...
    

    The link to a minimal working example is here:

    https://farm.pcibex.net/r/rAxemd/

    Thank you,
    -TS

    #10396
    Jeremy
    Keymaster

    Hello,

    This is because, in the absence of a selection, the choices array is empty, so the code in the Function element will crash when trying to reference the value of “the last choice” (presupposition failure: there is no choice to start with). What you can do to address the crash is return a dummy array in the absence of choices

    Regarding the specific feedback messages, you can handle them in two separate tests in wait, just like you tried to do: one that tests whether the Scale was interacted with, and one that checks the value on the Scale. The former will fail in the absence of a selection, so the latter just won’t matter (but won’t crash because of the dummy array; and we’ll make it succeed so as to not print its own feedback message in the absence of a choice)

    Now, because you want to provide different feedback depending on which test fails, neither should be the main test in the wait command and to which ands are appended, otherwise you’ll get inappropriate feedback. Instead, create a dummy main test which is always true, but conjoin to it (using and) a test on the Scale element (place the “select a value” feedback message in that test’s failure command) as well as a test on the Function element (place the “choose the right side instead” feedback message there). This way, the conjunction of all three tests will fail in either scenario (no choice, or invalid choice). You can place what’s common to both scenarios in the main test’s failure command to avoid redundancy:

    newButton("Next")
        .center()
        .print()
        .wait(
            newVar("dummy",1).test.is(1).and( // conjoin the test on the Scale
                getScale("Conclusion").test.selected()
                    .failure( getText("False").text("Select a value on the scale first") )
            ).and( // conjoin the test on the Function
                // We use the dummy array [-1,100] so that the second entry (index 1, ie value 100) is greater than 49
                newFunction( ()=>{const c=getScale("Conclusion")._element.choices; return (c[c.length-1]||[-1,100])[1]>=49;}).test.is(true)
                    .failure( getText("False").text("No, one would rather use the right-hand side of the scale.") )
            )
            .failure( // This runs when the conjunction of all three tests fails
                // All this is common to the no-choice and the low-value scenarios
                getText("False").hidden()
                ,
                newTimer("wait3", 100).start().wait()
                ,
                getText("False").visible()
                ,
                newTimer("wait4", 2000).start().wait()
                ,
                getText("False").hidden()
            )
        )
    ,
    // The code below is executed when the script moves past the wait command, ie when the test succeeds
    getText("Correct")
        .hidden()
    ,
    newTimer("wait1", 100)
        .start()
        .wait()
    ,
    getText("Correct").visible()
    ,
    newTimer("wait2", 4000)
        .start()
        .wait()

    Jeremy

    #10399
    bixprag
    Participant

    Hi, Jeremy!

    That works perfectly! Thank you so much for all your help!

    Best,
    TS

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.