I am trying to take dob and a date to work out the age. The check if that age is in the array c1ecg. I can get all the parts working except changing my birthday variable from dd/mm/yyyy to yyyy/mm/dd to calculate the age properly. The script doesnt error but the second brithday2 remains undefined when running it.
{
"Name": "Aviation",
"CreationDate": "2024-2-25",
"Commands": [
{
"Command": "store",
"Target": "40\t45\t50\t52\t54\t56\t58\t60\t62\t64\t66\t68\t70\t71\t72\t73\t74\t75\t76\t77\t78\t79\t80\t81\t82\t83\t84\t85\t86\t87\t88\t89\t90\t91\t92\t93\t94\t95\t96\t97\t98\t99\t100",
"Value": "c1ecg",
"Description": ""
},
{
"Command": "store",
"Target": "13/05/1988",
"Value": "birthday",
"Description": ""
},
{
"Command": "executeScript_Sandbox",
"Target": "\nvar newdate = ${birthday}.split(\"/\").reverse().join(\"-\");",
"Value": "birthday2",
"Description": ""
},
{
"Command": "executeScript_Sandbox",
"Target": "function getAge(dateString) {var today = new Date();var birthDate = new Date(dateString);var age = today.getFullYear() - birthDate.getFullYear();var m = today.getMonth() - birthDate.getMonth();if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())){age--;}return age;}return getAge(${birthday});",
"Value": "age",
"Description": ""
},
{
"Command": "echo",
"Target": "${age}",
"Value": "",
"Description": ""
},
{
"Command": "if",
"Target": "${c1ecg}.lastIndexOf(${age}) > -1",
"Value": "",
"Description": "the return value of .lastIndexOf() is -1 if the substring is not found in the string at all."
},
{
"Command": "echo",
"Target": "yes, it contains this string",
"Value": "blue",
"Description": ""
},
{
"Command": "end",
"Target": "",
"Value": "",
"Description": ""
}
]
}