The output is coming fine but the last condition fails!