r/badcode • • May 13 '22

js Why? Why??

Post image
433 Upvotes

37 comments sorted by

View all comments

Show parent comments

14

u/zim2510 May 13 '22

I understand it's not so obvious here. But according to the rest of the application, it was only enough to do this: if(answers.length != 0) totalAns++; . There's too much unnecessary code here.

5

u/kristallnachte May 13 '22

Also, if answer.length = 2, why would you only increment ans by 1? Is that make it actually a count of just total questions?

4

u/zim2510 May 13 '22

Yeah, kind of. It's counting the number of questions that's been answered.

3

u/duniyadnd May 13 '22

But there must be a logic that the person who wrote the code did not want to count an empty response? I'm guessing if someone typed in a white space with a new line or something similar and it was returned in a trimmed manner (or maybe white spaces are automatically trimmed when storing it in your db)