Reading question "Is Correct" in JavaScript

smiller7502 Community Member Posts: 181
I have a drag-and-drop question. I also have a JavaScript that needs to know whether that question was answered correctly. The question variable is a comma-delimited list showing ItemName-DropZoneName.

It's very cumbersome to write that value into an if statement. It would be easy to typo it, and especially easy to forget to update the script if the question changes. Yes, yes, QA and all that, I know -- but it would be much more robust if I could just write the script like if (question is correct) {}.

Lectora can do this in the If on an action, so I could create another variable and set it to "Correct" or "Incorrect", and doing so seems better than hard-coding the correct answer in the script.

But can I just read "question is correct" directly in the JavaScript without needing that extra variable?


  • timk
    timk Community Member Posts: 1,219 ♦ Idol ♦
    I'd go for that extra variable. If you look into the code Lectora produces for an "if correct" condition, you'll find it seems to hard-code the correct answer in the script.
  • zliquorman1276
    zliquorman1276 Community Member Posts: 67 ☆ Roadie ☆
    +1 what Tim suggested. Better to let Lectora automate where possible, because like you said, it's cumbersome to write and there's the added possibility of introducing typos/errors.

    I like to think of Lectora as an abstracted IDE for web content. Why not let it do the work where possible.