Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
Is it OK to use if statement in this form, or should i need to use something else to get result. I want to get effect if filtration is on 100 % then check cX if is on 100 % to add sign-ok not before filtration is on 100 %.
Just need opinion is it a good coding or I should change the approach?
if (filtration === 100) {
$(".filtration").removeClass('sign-no');
$(".filtration").addClass('sign-ok');
if (cX === 100){
$(".cX").removeClass('sign-no');
$(".cX").addClass('sign-ok');
if (stripping === 100) {
$(".stripping").removeClass('sign-no');
$(".stripping").addClass('sign-ok');
if (precipitation === 100) {
$(".precipitation").removeClass('sign-no');
$(".precipitation").addClass('sign-ok');
}
}
}
}
No issues. You can use. But if only first condition is true, then second condition will be checked and if it is true only it check the third condition and likewise.
Its okay, you can do it. But if you set a value on code quality, you should use maximal 2 depth in a block.
Must Code Quality Tools has a configuration for it.
ESLint
JSLint
....
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have been asked to show I have used these processes in my program but from looking up the definitions, I don't know what they mean. I am confident my program is complicated enough that it uses these processes, but I don't know exactly what they are. What would be an example of these processes used in javascript?
Unsure what you mean by custom function - but recursion is just a function that calls itself.
Example of recursion
countNumTimesToZero = (myNum, count = 0) => {
if (myNum - 1 === 0) return count + 1;
return countNumTimesToZero(myNum - 1, count + 1);
}
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
I have a Map = {'key - string', value as object} and a List[] and a String 'TEST',
Here I need to check two checking based on the String in the map and the Array,
For Example,
if(Map.has('TEST')) {
Need to do some logic
} else {
if(Array.includes('TEST') {
Need to do some manipulation
} else {
Need to do some manipulation
}
}
I have tried like above to achieve my need. Is it a best practice? Advice me.
if(Map.has('TEST')) {
Need to do some logic
} else if(Array.includes('TEST')) {
Need to do some manipulation
} else {
Need to do some manipulation
}
Use Else If
More Examples
EDIT1: Since you said you Need to check 2 Things Maybe this suits even more but im not sure your Question is very vague.
// || = OR
if(Map.has('TEST') || Array.includes('TEST')) {
Need to do some logic
} else {
Need to do some manipulation
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I'm trying to create a calculator which goes through 18 units. I wanted to make my code shorter by using a for loop. I thought something like this would work:
var i=0;
for (i=0;i<=18;i++)
{
if (Unit[i] = "P" or Unit[i] == "p")
{
UnitTotal[i] = 70;
SetCookie('UnitAns'[i],UnitAns[i]);
}
}
This doesn't work what am I doing wrong or what do I need to do differently?
Unit[i] = "P"
Unless it throws an exception because Unit isn't defined, this will always be true. = is an assignment, not a comparison.
or
or is not a keyword in JavaScript. The OR operator is ||.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I have more than 50 options but the user must select a maximum of 5 check boxes.
How could I restrict the user to select up to 5 check boxes?
Use a common if statement like so:
if ($('input[type="checkbox"]:checked').length > 5) {
alert('exceed 5')
}
Try $('input:checkbox:checked').length
Example
var total = $('input:checkbox:checked').length;
if (total <= 5) {
return true;
} else {
return false;
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
...but a glitch ain't one.
Hey there, I am still learning so I apologize for the simple question. I'm just trying out a hypothetical logic statement that would still make sense using javascript.
Example:
if (problems == 99) {
glitch != 1
}
Basically, I'd like it to mean "If I have 99 problems, a glitch isn't one of them" in the shortest code I can muster. Any help is really appreciated!!
Even shorter
glitch = problems !== 99;
Here's a more lyrical version:
if (problems.length === 99 && problems.indexOf("glitch")=== -1){
return "HOVA";
}
You are not setting glitch. Try glitch = false instead