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 1 year ago.
Improve this question
I have a problem I want the script not to run unless I am less than 5 trainqueue_barracks
but I put 100 here and it doesn't work either. What's wrong?
if ( document.document.getElementById("trainqueue_barracks") == null
|| document.document.getElementById("trainqueue_barracks").rows.length < 5
) {
As you have tagged jquery, you can simply do it like this:
if(!$('#trainqeueu_barracks').length || $('#trainqeueu_barracks tr').length < 5)
{
...
}
Note that !$('#trainqeueu_barracks').length will be always true in your case, so the second part won't actually matter. I think what you really need is:
if($('#trainqeueu_barracks tr').length < 5)
{
...
}
First off, you shouldn't need the first condition of your loop
document.document.getElementById("trainqeueu_barracks") == null
Also if you put 100 in their then it shouldn't work and your code is right. Unless you want it to run when rows.length is >= 5.
document.document.getElementById("trainqeueu_barracks").row.length >= 5
Is the opposite end of what you have.
Related
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 3 years ago.
Improve this question
I have attached the image:
From the above image, I have to filter such data "1565158223" and "4" at any place of receiver_id_1, receiver_id_2, sender_id but together.
I want to remove other data which contains "3","1", ect.
I want a solution with minimal code and minimum loops as there are too many records i get it.
I can check the condition like (receiver_id_1 == "1565158223" AND "sender_id" == "4") OR (receiver_id_2 == "1565158223" AND "sender_id" == "4") OR (receiver_id_2 == "1565158223" AND "receiver_id_1 " == "4") Like wise..
But I dont want to write several conditions over here.
Please anybody help me to resolve it.
If you can use the features of es6 try this(we suppose your array is items):
filtered_items = items.filter(item =>
[1565158223,4].indexOf(parseInt(item['receiver_id_1'])) > -1 &&
[1565158223, 4].indexOf(parseInt(item['receiver_id_2'])) > -1 &&
[1565158223, 4].indexOf(parseInt(item['sender_id'])) > -1
)
Notice that it won't change the origin items and just filtered_items is your final filtered items.
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
....
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 does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 7 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
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.
Improve this question
What is right syntax to check values based on if condition using && and ! operator?
I am getting an error and am confused by !.
main.js
if($scope.sysRecomm === 'High' && !($scope.busDecision==='21')){
$scope.disableSubmitButton = true;
}
if($scope.sysRecomm === 'High' && $scope.busDecision !== '21'){
$scope.disableSubmitButton = true;
}
use like this:
if($scope.sysRecomm === 'High' && $scope.busDecision !='21'){
&& requires both side of the operator to hold TRUE to return true value of entire expression.
For example:
if(X && Y) {
// this block is executed only if X & Y are true
}
Coming to negation operator ! , it negative the truth value of whatever expression it is attached to:
For example if negation operator is used inside a if block:
if(!X){
// executed only when X is false.
}
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
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.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
I am working on a javascript quiz programme , and i have return a function to check what difficulty level the user wants . below is the code and the jsfiddle :
function getdifficulty(){
var j = 0;
var level = prompt('what level would you like 1. easy 2. intermediate 3.hard' , '')
if(level == easy){
j = questionseasy[0];
}
else if(level == intermediate){
j = questionseasyenuf[0];
}
else{
j = questionshard[0];
}
alert("you did it");
}
getdifficulty();
Jsfiddle here
now the problem is the the alert is not showing up ? whats the problem with this short piece of code ? (In the real programme though i will not use an alert but return statement , i even tried using document.write or console.log but none worked) .
prompt() returns a string. You need to make your comparisons strings by encapsulating them in double quotes (").
function getdifficulty(){
var level = prompt('what level would you like 1. easy 2. intermediate 3.hard' , '')
if(level == "easy"){
alert("easy");
}
else if(level == "intermediate"){
alert("intermediate");
}
else{
alert("hard");
}
}
getdifficulty();
JSFiddle
Also, in the implementation you have provided in your post, questionseasy, questionseasyenuf, and questionshard will not be defined. You must bring them into the scope of the function before you can start using them.
questionseasy is undefined. You can trace javascript as it runs in your browser console and see this.