javascript OR ||

From: CHYRON (DSMITHHFX)22 Jan 2015 21:51
To: ALL1 of 15
Why ain't this work:
Code: 
if ( oclient == 'ap' || 'cgov' || 'chs' || 'fm' || 'id' || 'sm' )
From: 99% of gargoyles look like (MR_BASTARD)22 Jan 2015 21:57
To: CHYRON (DSMITHHFX) 2 of 15
Have you tried this?
Code: 
if ( oclient == ('ap' || 'cgov' || 'chs' || 'fm' || 'id' || 'sm' ))
From: Chris (CHRISSS)22 Jan 2015 22:11
To: CHYRON (DSMITHHFX) 3 of 15
Do you have to do
Code: 
if ( oclient == 'ap' || oclient == 'cgov' || oclient == 'chs' || oclient == 'fm' || oclient == 'id' || oclient == 'sm' )
From: CHYRON (DSMITHHFX)22 Jan 2015 22:22
To: Chris (CHRISSS) 4 of 15
Now see, I hate that. I went with a switch statement instead. Can't fathom why the if statement doesn't work with that syntax though.
EDITED: 22 Jan 2015 22:23 by DSMITHHFX
From: Peter (BOUGHTONP)22 Jan 2015 22:23
To: CHYRON (DSMITHHFX) 5 of 15
What Chris said, or with regex:
if ( oclient.search(/^(?:ap|cgov|chs|fm|id|sm)$/) !== -1 )
or jQuery;
if ( jQuery.inArray( oclient , ['ap','cgov','chs','fm','id','sm'] ) )

Though this sort of thing can often be better handled another way entirely, (depending on what is actually being done).

Also, "oclient" is almost certainly a shit variable name and should be changed.

From: CHYRON (DSMITHHFX)22 Jan 2015 22:26
To: Peter (BOUGHTONP) 6 of 15
It's a great name. It's an awesome name. What would you suggest, just so I'll never use it?

The regex idea is good, though.
EDITED: 22 Jan 2015 22:26 by DSMITHHFX
From: CHYRON (DSMITHHFX)22 Jan 2015 22:27
To: 99% of gargoyles look like (MR_BASTARD) 7 of 15
Can't remember. Probably. Maybe.


edit: ok, I just tried it. didn't work.
EDITED: 22 Jan 2015 22:31 by DSMITHHFX
From: Peter (BOUGHTONP)22 Jan 2015 22:29
To: CHYRON (DSMITHHFX) 8 of 15
I can't say - it's too shit a name to know what it's for - but anything which gives the 'o' a precise yet concise meaning will do. Something that a different person can look at and know what it is for.
From: 99% of gargoyles look like (MR_BASTARD)22 Jan 2015 22:30
To: CHYRON (DSMITHHFX) 9 of 15
I figured it wasn't working because it's essentially taking the first comparison, then running the other OR statements separately, which is why I suggested parentheses around the comparison to the right (whatever that's called). 
From: CHYRON (DSMITHHFX)22 Jan 2015 22:39
To: Peter (BOUGHTONP) 10 of 15
o means "other". You'd have to search for "other" instances in the script to figure it out. If you happened to be looking at the script (don't worry, you won't), you might notice I'm in the habit of using similar variables throughout, mainly to reduce verbosity and make things easier to spot. Like using "e" for "event", or "i" for whatever "i" stands for ("idiot"?). I also use comments. Thus "oclient" makes it's first appearance under 
Code: 
// "OTHER" [more commenty stuff you don't need to know]
(there's another variable "client" preceding that section in the script).

You could probably manage it, I concede that "others" might not. I can sleep knowing that.
EDITED: 22 Jan 2015 22:40 by DSMITHHFX
From: Peter (BOUGHTONP)22 Jan 2015 22:52
To: CHYRON (DSMITHHFX) 11 of 15
Have you ever encountered a faulty traffic signal that was stuck on red?
From: Ally22 Jan 2015 23:06
To: CHYRON (DSMITHHFX) 12 of 15
Probably really inefficient code, but before now I've done
 
Code: 
if (['ap','cgov','chs'].indexOf(oclient) > -1) {

Oh, and your original statement doesn't work because || basically starts a new if statement. So you were saying "if oclient equals 'ap' or if 'cgov' or if 'chs'", and because Javascript is annoying nice it tries to convert it into something that'll work - a string is "non-false", so it'll return true.

EDITED: 22 Jan 2015 23:08 by ALLY
From: CHYRON (DSMITHHFX)23 Jan 2015 02:20
To: Peter (BOUGHTONP) 13 of 15
I don't drive.
From: Peter (BOUGHTONP)24 Jan 2015 01:55
To: CHYRON (DSMITHHFX) 14 of 15
Well yes, why would you when you can crawl.

I mean, you've been crawling for quite a while, you're pretty good at it, can shuffle up quite a pace on all fours. It makes perfect sense to continue doing the same thing, you'll get somewhere in the end, even if everyone else has long since moved on.

From: CHYRON (DSMITHHFX)24 Jan 2015 19:06
To: Peter (BOUGHTONP) 15 of 15