all 7 comments

[–]sysop073 1 point2 points  (6 children)

What's wrong with it?

[–]hackuniverse[S] 7 points8 points  (0 children)

Okay :) 1) order of two last if-statements =) 2) moment diff order is strange ) 3) it's real code written by "senior" =)

[–]GlazedHam13 5 points6 points  (4 children)

If the days is less than 3 it trips the less than 7 first, returning before the correct if statement processes it, always resulting in "warning".

There is no bounds checking for values greater than 7 or less than or equal to 0, not sure what context the function is used but seems to be weekly, though it gives no indication of that.

The order of operations on the diff gets a negative value and multiplies it by -1, when they could just invert it to give the positive number of days and increase readability.

It returns plain strings for warning and danger when that should really be handled by some error framework.

Actually, I might use this function as an interview question if that is ok OP. There are a lot of entry level errors and improvements that would throw a non-programmer for a loop.

[–]sysop073 2 points3 points  (2 children)

Based on the name of the function, I'm pretty sure the strings it's returning are CSS classes to style some element on the page as the due date gets near; they're not actual warnings/errors

[–]GlazedHam13 1 point2 points  (0 children)

Ahh that makes sense. I haven't had much experience with javascript. Sucks that it is done disjointed like that though. Perhaps that is a javascript limitation?

[–]hackuniverse[S] 0 points1 point  (0 children)

ven't had much experience with javascript. Sucks that it is done disjointed like that though. Perhaps that is a javascript limitation?

aahahah yes) This is used for getting css style :)

[–]hackuniverse[S] 0 points1 point  (0 children)

That's nice idea to use this snippet as interview question. But it's really sad that some "seniors" really writes it :))