We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Your logic is inelegant; you are needlessly checking for both AM and PM. Using an else-if statement after checking PM ensures that the AM logic will only be reached/tested if the PM check failed, thus eliminating needless/redundant condition checking. Here is modified logic:
I would also recommend you follow the best practice of always bracketing the 'then' code in your conditional statements (if(){}), regardless of how little code it may contain.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Time Conversion
You are viewing a single comment's thread. Return to all comments →
Your logic is inelegant; you are needlessly checking for both AM and PM. Using an else-if statement after checking PM ensures that the AM logic will only be reached/tested if the PM check failed, thus eliminating needless/redundant condition checking. Here is modified logic:
I would also recommend you follow the best practice of always bracketing the 'then' code in your conditional statements (if(){}), regardless of how little code it may contain.