I have been able to implement a sort of password for a javascript package I am using, called jsPsych 5.0. I used a loop function and a survey-text plugin as follows:
var password = { type: 'survey-text', questions: [{prompt: "Please enter the password provided to you by email", rows: 3, columns: 40}], };var loop_node_password = { timeline: [password], loop_function: function(data){ var Responses = JSON.parse(data[0].responses); if (Responses.Q0 == "mypassword"){ return false; }else{ return true; alert("Please enter the correct password") } }};timeline.push(loop_node_password);
Now, the problem I have is that var Responses = JSON.parse(data[0].responses); is returning Responses = {"Q0":"mypassword"}. Trying to access it using Responses.Q0 does not seem to work. Any help with this please? I need to access the value of the key Q0, I am not sure how to search for that in internet. I have tried Responses[Q0], Responses["Q0"], nothing works. All I need is to get the value of the "Q0":"mypassword" - i.e. mypassword. Any help please
All the best and thank you,
Dritan
JavaScriptPHP
Last Comment
Dritan Nikolla
8/22/2022 - Mon
OMC2000
try to validate responses:
var key;for (key in Responses) { if (Responses .hasOwnProperty(key)) { alert(key + " = " + Responses[key]);// console.log(key + " = " + Responses[key]); }}
Open in new window