How to convert this example of nested ternary if-else to if-else loop

join shbcf.ru