Skip to content
Advertisement

Why is my code not printing anything? Is there something wrong with my loops?

I have the following code in a project called PostOffice:

JavaScript

}

But when I run it, it prints nothing. It just says<terminated> and the output is blank. I tried fixing it and ran it several times over and over again, but the result is the same. Is there something wrong with my code? If so, what can I do to resolve it? And how would I prevent this from happening again?

Advertisement

Answer

It says <terminated> because your input doesn’t match any if condition, so the program terminates with no output. Add a simple print at the end of your main function to report when there is no match like:

JavaScript

Also as mentioned in the comment, parse the input at the beginning and then process it. I refactored your code:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement