- Posts: 1
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
$(document).ready(function() { function add(accumulator, val) { var numericVal = Number(val); var logicValue = (numericVal === 0) ? 1 : 0; return accumulator + logicValue; } // Valid total count to be redirected to Part 2; var n_valid = 5; // Valid conditions. False evaluate to 0 and true to 1. // Since we have only 5 true conditions, the sum when all // the choices are valid must be equal to n_valid; var valid = [ 1 - Number("{SCR01.NAOK>=18}"), // True; 1 - Number("{SCR01.NAOK<=80}"), // True; strcmp("{SCR03.NAOK}", "Y"), // True; strcmp("{SCR05.NAOK}", "AO01"), // True; strcmp("{SCR08.NAOK}", "AO01") // True; ]; var invalid = [ strcmp("{SCR02.NAOK}", "AO01"), strcmp("{SCR02.NAOK}", "AO02"), strcmp("{SCR031.NAOK}", "AO01"), strcmp("{SCR031.NAOK}", "AO02"), strcmp("{SCR032.NAOK}", "AO01"), strcmp("{SCR032.NAOK}", "AO02"), strcmp("{SCR033.NAOK}", "AO01"), strcmp("{SCR033.NAOK}", "AO02"), strcmp("{SCR06_SQ002.NAOK}", "AO04"), strcmp("{SCR06_SQ002.NAOK}", "AO05"), strcmp("{SCR06_SQ003.NAOK}", "AO04"), strcmp("{SCR06_SQ003.NAOK}", "AO05"), strcmp("{SCR06_SQ004.NAOK}", "AO04"), strcmp("{SCR06_SQ004.NAOK}", "AO05"), strcmp("{SCR06_SQ006.NAOK}", "AO04"), strcmp("{SCR06_SQ006.NAOK}", "AO05"), strcmp("{SCR06_SQ007.NAOK}", "AO04"), strcmp("{SCR06_SQ007.NAOK}", "AO05") ]; const valid_count = valid.reduce(add, 0); const invalid_count = invalid.reduce(add, 0); console.log(valid_count); console.log(invalid_count); if (valid_count === n_valid){ if (invalid_count === 0) { console.log("Validated - User meets all criteria."); } } else { console.log("Validation Failed - User does not meet criteria."); } });
Please Log in to join the conversation.
Please Log in to join the conversation.