I have been tasked with re-writing some code for a client reservation form and I was hoping someone could explain the following syntax. I know its basically like an if statement but the way it is set up is a little obscure to me since I am somewhat new to JavaScript:
testDate.setHours
(
    ampm.value=="AM"?
    (timestr[0]==12?0:timestr[0]=timestr[0]):
    (timestr[0]==12?12:timestr[0]=timestr[0]+12)
);
The whole reasoning behind this problem that I am working on is to take a value in for the reservation time. It parses the string into an array where timestr[0] is the hour value. Based on AM/PM and the value the user inputs, it will do its conversion to set the hours to military time. I am not sure that this is even working correctly.
If someone could analyze this code, explain the syntax to me (?,:, etc.) and tell me if this is the appropriate way to convert the hours I would greatly appreciate it.
Thank you!
Dave
EDIT :
Also, would this be an identical way of writing it, just easier to understand:
if(ampm.value=="AM")
{
    if(timestr[0]==12)
    {
        timestr[0] = 0;
        testDate.setHours(timestr[0]);
    }
    else
    {
        testDate.setHours(timestr[0]);
    }
}
else
{
    if(timestr[0]==12)
    {
        testDate.setHours(timestr[0]);
    }
    else
    {
        timestr[0] = timestr[0] + 12;
        testDate.setHours(timestr[0]);
    }
}
 
     
    