PennController for IBEX › Forums › Support › Feedback based on slider scale selection
Tagged: slider
- This topic has 5 replies, 2 voices, and was last updated 2 years ago by
bixprag.
-
AuthorPosts
-
March 13, 2023 at 2:32 pm #10372
bixprag
ParticipantHello,
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
March 14, 2023 at 4:34 am #10373Jeremy
KeymasterHello,
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
March 14, 2023 at 1:36 pm #10391bixprag
ParticipantHello, Jeremy,
thank you very much. It works perfectly!
Best,
TSMarch 15, 2023 at 10:31 am #10395bixprag
ParticipantHello 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,
-TSMarch 15, 2023 at 1:17 pm #10396Jeremy
KeymasterHello,
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 choicesRegarding 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 whichand
s are appended, otherwise you’ll get inappropriate feedback. Instead, create a dummy main test which is always true, but conjoin to it (usingand
) a test on the Scale element (place the “select a value” feedback message in that test’sfailure
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’sfailure
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
March 16, 2023 at 2:54 pm #10399bixprag
ParticipantHi, Jeremy!
That works perfectly! Thank you so much for all your help!
Best,
TS -
AuthorPosts
- You must be logged in to reply to this topic.