1
message += days + " day" + ( days==1 ? '':'s' ) + ", ";

If my counter comes to 1 month and ZERO day, it writes dayS, of course. How can I pass a "OR" operator into this code?

I tried:

( (days==1 ? '':'s' ) || (days==0 ? '':'s'))

and:

( days==1||0 ? '':'s' )

Both of them show an S at value "0"

5
  • 1
    if you are not comfortable with this format, why don't you simply use if..else format Commented Nov 26, 2012 at 6:52
  • (( days==1 || days==0) ? '':'s' ) Commented Nov 26, 2012 at 6:53
  • Do you mean ( days==0 || days==1 ? '':'s ) ? Commented Nov 26, 2012 at 6:53
  • (days==1 || days == 0 ? '':'s' ) Commented Nov 26, 2012 at 6:55
  • Please note that as opposed to French, in English a count of zero is attributed a plural spelling because the English grammar follows a logic close to: only one is singular, everything else is plural. Reference: english.stackexchange.com/questions/13073/… Commented Apr 28, 2018 at 11:32

4 Answers 4

2

why don't you try:

days < 2

unless there's a chance of negative number of days

Sign up to request clarification or add additional context in comments.

1 Comment

:) off course ! I have tested that day>0 in a global if...else before this code :) THX
1

"0 days" is correct, but if you really want it: (days == 0 || days == 1 ? '' : 's')

Alternatively: (days <= 1 ? '' : 's') (since you can't have a negative or non-integer number of days.

Or you could do this to the whole line:

if( days) message += days + " day" + (days==1 ? '' : 's') + ", ";

3 Comments

1 is the only number that results in a singular noun. Everything else is plural. Even 1.1 seconds is correct, for example.
Even 1.0 seconds vs. one second, provided you say the "point zero" at the end. The s "plural" ending is not technically a plural indicator but instead a non-singular indicator.
Ok, so exist singular, plural and non-singular. Three state logic.
1

Write it like this

message += days + " day" + ( days<=1 ? '':'s' ) + ", ";

Comments

1

Try (( days==1|| days == 0) ? '':'s' )

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.