If statement not working properly even though everything is right
You should always test your check with hardcoded values before using user values
https://jsfiddle.net/czw72sj1/
var seeprices = "preiseaendern";
var rights = "Individuell"; //Value of Combobox
alert(seeprices + " " + rights); // seeprices outputs 'preiseaendern' and rights outputs 'Individuell'
if (rights === "Individuell" && seeprices === "preiseaendern"){
alert("it works...");
}
When using that it works correctly, so this means it's your user input that is not working 100% so as @Rajesh said to use String.trim()
So 2 things stand out at me one your getting text out of HTML while allowing HTML codes,$( "#seeprice").html();
should be $( "#seeprice").text();
as this will strip any HTML or spacing arround the text your need but it should still be .trim()
ed
var seeprices = $( "#seeprice").text().trim();
var rights = $( "#rights" ).val().trim();
If this still does not work as it might not i'm guessing because i can't see your HTML create a JSFiddle with the #seeprice
element and the #rights
Combobox so we can see what's going wrong with reading the DOM values.
Why is my else/if statement not working right in javascript?
Your "else" have an arguments, but this is not right
const calculateSleepDebt = () => {
const actualSleepHours = getActualSleepHours()
const idealSleepHours = getIdealSleepHours()
if (actualSleepHours === idealSleepHours) {
console.log('You got the perfect amount of sleep!')
}
else if (actualSleepHours > idealSleepHours) {
console.log('You got too much sleep!')
}
else{
console.log('You did not get enough sleep!')
}
};
Try this! Sorry for my english <3
Why is if statement not working
Although user154248's answer is (in parts at least) correct, you might be interested in why...
The reason is that operator!=
has higher precedence (i. e. is evaluated before) operator||
. So your if clause is equivalent to if((i != 0) || 1)
.
Additionally, any value unequal to 0 (null/zero) is evaluated to true
, if used in an expresstion expecting a boolean parameter, so you get if((i != 0) || true)
. And now, what ever i != 0
evaluates to, the overall expression x || true
will result in true
.
Finally – we are back at user154248's answer...
However, there is a problem left: i != 0 || i != 1
will also always evaluate to true: If i equals 0, i != 1
evaluates to true, if i equals 1, i != 0
does so...
What you actually need is i != 0 && i != 1
.
C++ if/else if statement not working correctly
cin >> input;
does not read whitespaces. You need to use std::getline
.
getline(cin, input);
Or in IF statement not working properly
This is the correct behavior, you need to use &&
.
The reason is that the count is fixed number, let's say n. Now the condition reads:
n is not 3 or n is not 4.
Given n is 4, this means it is not 3, thus the test succeeds and vice versa.
A compiler can't detect this is trivially true, because between the two if
statements, the Count()
might change (for instance in a multithreading setting where the second thread would add/remove something to/from the collection). I agree however some analysis tools could be capable in some conditions to detect such trivial behavior. In general however such analysis can't be implemented because of Rice's theorem.
If you use &&
, the expression reads:
n is not 3 and n is not 4.
Thus both conditions should be true. In other words only if n is less than three and greater than 4, the condition holds.
Java IF statements not working properly
Try this,
- use
==
for comparison - no space between
<=
and>=
- group
or
conditions in parenthesis - use separate variable for each comparison
- use
<=
not=<
, use>=
instead of=>
use
genderint
andageint
variables for int comparisonif ((genderint == 0 || genderint ==1) && (ageint >=18 && ageint < 26)) {
group = "Category A";
} else if(genderint == 0 && ageint >= 27 && ageint < 60){
group = "Category B";
} else if(genderint == 1 && ageint >= 27 && ageint < 60) {
group = "Category C";
} else if((genderint == 0 || genderint == 1) && ageint >= 60) {
group = "Category D";
} else if((genderint == 0 || genderint ==1) && ageint <18){
JOptionPane.showMessageDialog(null,"Sorry, you're too young");
}
If/else is not working properly with using OnInitiliazedAsync in Blazor C#
Right now you have two states, either the list is null/empty, or the list has at least one entry. The problem is that "null" means the list is loading, but "empty" means the list has loaded and has zero entries. You're considering those the same.
You need to have three states.
- The list is loading (value is null)
- The list has loaded but has no entries (value is empty list)
- The list has loaded and has at least one entry
Simply modify your else
to an else if
@if (Products != null && Products.Any())
{
@foreach (var product in Products)
{
#MyCode
}
}
else if (Products != null && !Products.Any())
{
<h2>This Store has no Products :)</h2>
}
If Products
is null, it won't activate the if or else if, and print nothing. You could add an else
afterwards which prints "Loading..." if you wish.
Note, this all works because of the assumption that Store.GetStoreProducts
should NEVER return null.
Related Topics
Lambdas and Capture by Reference Local Variables:Accessing After the Scope
Covariant Return Type and Type Conversion
How to Use Unicode Range in C++ Regex
How to Convert from Lpctstr to Std::String
Static Variable in the Class Declaration or Definition
Cmake - Global Linker Flag Setting (For All Targets in Directory)
Efficient Multiply/Divide of Two 128-Bit Integers on X86 (No 64-Bit)
Effective Use of C++ Iomanip Library
How to Pass a Std::Function Object to a Function Taking a Function Pointer
C++11 Std::Threads VS Posix Threads
References Needed for Implementing an Interpreter in C/C++