if-statement

jQuery if statement depending on width in px

二次信任 提交于 2020-01-02 06:58:39
问题 I'm quite new to jQuery, could someone please tell me if I have expressed the above 'if' statement correctly? I basically want something to run if the width of my variable equals 900px. My variable is var $brewapp = $('#brewapp'); Thanks. if (($brewapp).width == '900px') { //what i want it to do } 回答1: .width is a function, that returns a number. So your test should look like this: if ($brewapp.width() === 900) I suggest the Mozilla Javascript docs if you want to deepen your JS knowledge. 回答2

In Objective-C Check an array of Boolean Values and see if at least ONE is YES

£可爱£侵袭症+ 提交于 2020-01-02 03:48:26
问题 I have a mutable array of Boolean values and I want to check to see if ANY of the values are YES. At present I am creating another array alongside this one which is always ALL False like so; [MyArray addObject:[NSNumber numberWithBool:switchInput]]; [MyAllNoArray addObject:[NSNumber numberWithBool:NO]]; The user does some bits and the some of the objects in MyArray may become YES, I then use the below to see if ANY are true or not. if([MyArray isEqualToArray:MyAllNoArray]) I am just wondering

Checking for membership in an Erlang guard

感情迁移 提交于 2020-01-02 03:39:28
问题 What is the simplest way to write an if statement in Erlang, where a part of the guard is member(E, L) , i.e., testing if E is a member of the list L ? The naive approach is: if ... andalso member(E,L) -> ... end But is does not work becuase, if I understand correctly, member is not a guard expression. Which way will work? 回答1: Member functionality is, as you say, not a valid guard. Instead you might consider using a case pattern? It's possibly to include your other if-clauses in the case

logical(0) in if statement

我与影子孤独终老i 提交于 2020-01-02 03:15:53
问题 This line: which(!is.na(c(NA,NA,NA))) == 0 produces logical(0) While this line if(which(!is.na(c(NA,NA,NA))) == 0){print('TRUE')} generates: Error in if (which(!is.na(c(NA, NA, NA))) == 0) { : argument is of length zero Why there is an error? What is logical(0) 回答1: logical(0) is a vector of class logical with 0 length. You're getting this because your asking which elements of this vector equal 0: > !is.na(c(NA, NA, NA)) [1] FALSE FALSE FALSE > which(!is.na(c(NA, NA, NA))) == 0 logical(0) In

Two conditions in if

淺唱寂寞╮ 提交于 2020-01-01 23:52:33
问题 I'm trying to write a script which will read two choices, and if both of them will be "y" I want it to say "Test Done!" and if one or both of them won't be "y" I want it to say "Test Failed!" Here's what I came up with: echo "- Do You want to make a choice ?" read choice echo "- Do You want to make a choice1 ?" read choice1 if [ "$choice" != 'y' ] && [ "$choice1" != 'y' ]; then echo "Test Done !" else echo "Test Failed !" fi But when I answer both questions with "y" it's saying "Test Failed!"

How to have the Xcode 3.1 compiler warn of assignment operator in an if statement?

纵饮孤独 提交于 2020-01-01 19:59:09
问题 I've tried searching the documentation and the internet as best as I'm able, but I haven't been able to get the Xcode compiler to issue a warning if the assignment operator is used in an if statement. I'm coming from RealBasic, where I've got an extremely strong habit of typing this sort of comparison: if x = 5 then ... In C, of course, that syntax assigns x the value of 5 then tests the result to see if it's nonzero, and the "correct" operator is: if (x == 5) { ... } I've found several

Build dynamic SQL with “AND” expressions without confusing nested conditionals?

二次信任 提交于 2020-01-01 16:52:48
问题 I'm fairly new to php and coding in general. I have a series of conditions I need to test if they are set. They are $option1, $option2, $option3 if (isset($option1)){ if (isset($option2)){ if (isset($option3)){ $query = "SELECT * FROM Group WHERE FirstOption = '$option1' AND SecondOption = '$option2' AND ThirdOption = '$option3'"; } else { $query = "SELECT * FROM Group WHERE FirstOption = '$option1' AND SecondOption = '$option2"; } } else { $query = "SELECT * FROM Group WHERE FirstOption = '

How to code these conditional statements in more elegant & scalable manner

大兔子大兔子 提交于 2020-01-01 09:22:44
问题 In my software, I need to decide the version of a feature based on 2 parameters. Eg. Render version 1 -> if (param1 && param2) == true; Render version 2 -> if (!param1 && !param2) == true; Render version 3 -> if only param1 == true; Render version 4 -> if only param2 == true; So, to meet this requirement, I wrote a code which looks like this - if(param1 && param2) //both are true { version = 1; } else if(!param1 && !param2) //both are false { version = 2; } else if(!param2) //Means param1 is

How to code these conditional statements in more elegant & scalable manner

走远了吗. 提交于 2020-01-01 09:22:07
问题 In my software, I need to decide the version of a feature based on 2 parameters. Eg. Render version 1 -> if (param1 && param2) == true; Render version 2 -> if (!param1 && !param2) == true; Render version 3 -> if only param1 == true; Render version 4 -> if only param2 == true; So, to meet this requirement, I wrote a code which looks like this - if(param1 && param2) //both are true { version = 1; } else if(!param1 && !param2) //both are false { version = 2; } else if(!param2) //Means param1 is

If statement simplification in C#

时光怂恿深爱的人放手 提交于 2020-01-01 09:21:50
问题 I have a line of code that looks like this: if (obj is byte || obj is int || obj is long || obj is decimal || obj is double || obj is float) Is it possible to write something more elegant than this? Something like: if (obj is byte, int, long) I know that my example isn't possible, but is there a way to make this look "cleaner"? 回答1: You could write an extension method on object to give you syntax like: if (obj.Is<byte, int, long>()) { ... } Something like this (use multiple versions for fewer