Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

Calculating correct response in OSWEB using js

Hello!,

I have had to update my experiment so that it is compatible with OSWEB and this has left me with a few issues.

Rather than use a linked sketchpad for responses I am now using a custom form with buttons however the output for responses is 'yes' or 'no'.

I have a variable for the correct response in the loop and would like to somehow create a new variable that simply states 1 for correct response or 0 for incorrect response.

So for example if the variable for correct response in the pool is anger and the variable anger_rb is 'yes' then correct_response would = 1.

I have tried to write an inline javascript for this but have got completely lost as I have very limited js knowledge.

Thanks in advance for any help!

Comments

  • Hi @predictorgilt,

    I'd have to see your task or a simplified version of it to test a solution but, generally speaking, as long as what you're after is setting a variable to a certain value based on the values of other variables, in Javascript within OSWeb, you can do it with "if" statements. Looking up "If then else Javascript" in google will bring up lots of pages where you can find how the syntax works.

    There is something a little odd in your request, though, since you seem to want to define the value of correct_response based partly on the value of that same variable.

    If you're after a variable that will be 1 or 0 based on whether the response is correct or incorrect respectively, you can get it from vars.correct. This variable, in a trial of your loop, will take the value 1 or 0 as long as you've defined what the correct response is in that trial (either manually through code, or by including a "correct_response" column in your loop.

    If, for some reason (e.g., you want to define the correct response dynamically based on several conditions), you wanted to define the score for each response, you could do it using some along those lined (I'm relatively new to Javascript myself):

    if (vars.correct_response == 'anger" and vars.anger_rb == 'yes') {
       vars.correct = 1
    } else {
       vars.correct = 0
    } 
    

    If for some reason you don't want to use the reserved vars.correct variable and want to create your own, you can do so:

    if (vars.correct_response == 'anger" and vars.anger_rb == 'yes') {
       vars.anger_score = 1
    } else {
       vars.anger_score = 0
    } 
    

    You would then be able to call upon the content of that variable in OSWeb objects (e.g., feedback object) using "[anger_score]".

    If you'd like to see some more advanced examples of Javascript used to calculate scores based on conditions, have a look at this thread; you might find some useful pointers there: https://forum.cogsci.nl/discussion/comment/24233#Comment_24233

    Hope this helps!

    Fabrice.

    Buy Me A Coffee

  • Thank you very much for the response ! I shall try this out now.

Sign In or Register to comment.