Codingjavascript OR ||

 

Press Ctrl+Enter to quickly submit your post
Quick Reply  
 
 
  
 From:  CHYRON (DSMITHHFX)  
 To:  ALL
41370.1 
Why ain't this work:
Code: 
if ( oclient == 'ap' || 'cgov' || 'chs' || 'fm' || 'id' || 'sm' )

----
New giveaways: “Learn Ruby the Hard Way”
0/0
 Reply   Quote More 

 From:  99% of gargoyles look like (MR_BASTARD)  
 To:  CHYRON (DSMITHHFX)     
41370.2 In reply to 41370.1 
Have you tried this?
Code: 
if ( oclient == ('ap' || 'cgov' || 'chs' || 'fm' || 'id' || 'sm' ))

truffy.gifbastard by name
bastard by nature

0/0
 Reply   Quote More 

 From:  Chris (CHRISSS)  
 To:  CHYRON (DSMITHHFX)     
41370.3 In reply to 41370.1 
Do you have to do
Code: 
if ( oclient == 'ap' || oclient == 'cgov' || oclient == 'chs' || oclient == 'fm' || oclient == 'id' || oclient == 'sm' )

Me
0/0
 Reply   Quote More 

 From:  CHYRON (DSMITHHFX)  
 To:  Chris (CHRISSS)     
41370.4 In reply to 41370.3 
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.

----
New giveaways: “Learn Ruby the Hard Way”
0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  CHYRON (DSMITHHFX)     
41370.5 In reply to 41370.1 
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.

0/0
 Reply   Quote More 

 From:  CHYRON (DSMITHHFX)  
 To:  Peter (BOUGHTONP)     
41370.6 In reply to 41370.5 
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.

----
New giveaways: “Learn Ruby the Hard Way”
0/0
 Reply   Quote More 

 From:  CHYRON (DSMITHHFX)  
 To:  99% of gargoyles look like (MR_BASTARD)     
41370.7 In reply to 41370.2 
Can't remember. Probably. Maybe.


edit: ok, I just tried it. didn't work.

----
New giveaways: “Learn Ruby the Hard Way”
0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  CHYRON (DSMITHHFX)     
41370.8 In reply to 41370.6 
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.
0/0
 Reply   Quote More 

 From:  99% of gargoyles look like (MR_BASTARD)  
 To:  CHYRON (DSMITHHFX)     
41370.9 In reply to 41370.4 
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). 

truffy.gifbastard by name
bastard by nature

0/0
 Reply   Quote More 

 From:  CHYRON (DSMITHHFX)  
 To:  Peter (BOUGHTONP)     
41370.10 In reply to 41370.8 
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.

----
New giveaways: “Learn Ruby the Hard Way”
0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  CHYRON (DSMITHHFX)     
41370.11 In reply to 41370.10 
Have you ever encountered a faulty traffic signal that was stuck on red?
0/0
 Reply   Quote More 

 From:  Ally  
 To:  CHYRON (DSMITHHFX)     
41370.12 In reply to 41370.1 
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.

0/0
 Reply   Quote More 

 From:  CHYRON (DSMITHHFX)  
 To:  Peter (BOUGHTONP)     
41370.13 In reply to 41370.11 
I don't drive.

----
New giveaways: “Learn Ruby the Hard Way”
0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  CHYRON (DSMITHHFX)     
41370.14 In reply to 41370.13 
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.

0/0
 Reply   Quote More 

 From:  CHYRON (DSMITHHFX)  
 To:  Peter (BOUGHTONP)     
41370.15 In reply to 41370.14 

----
New giveaways: “Learn Ruby the Hard Way”
0/0
 Reply   Quote More 

Reply to All    
 

1–15

Rate my interest:

Adjust text size : Smaller 10 Larger

Beehive Forum 1.5.2 |  FAQ |  Docs |  Support |  Donate! ©2002 - 2024 Project Beehive Forum

Forum Stats