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 8 years ago.
Improve this question
this is my markup
http://i.imgur.com/j2rhUH3.png
I tried $('.post-form').find('p:first').text().indexOf("Logged") !=''), and try to detect whether Logged is set or not, but I got this error Unexpected token !
You get error Unexpected token ! because your statement
$('.post-form').find('p:first').text().indexOf("Logged") !='')
is not complete.
Use if condition and indexOf as shown below :-
if( $('.post-form').find('p:first').text().indexOf("Logged") > -1)
The indexOf() method returns the position of the first occurrence of a specified value in a string.
This method returns -1 if the value to search never occurs
indexOf returns integer not string.
It returns the position where the specified searchvalue occurs for the first time, or -1 if it never occurs.
You get error Unexpected token ! because your statement
$('.post-form').find('p:first').text().indexOf("Logged") !='')
is incomplete.
Following should work:
if($('.post-form').find('p:first').text().indexOf("Logged") >= 0){
...
}
See DEMO here.
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 2 years ago.
Improve this question
This works
console.log(comments[i].includes("NEW ENTRY"));
This doesn't work
while ((comments[i].includes("NEW ENTRY")) == false) {
//Some code
}
With the little information you give us, I would say that you do not manage the incrementation of your variable i.
const arrStr = ["hello", "asdf", "dfa"]
arrStr[0].includes("hel") // -> true
arrStr[1].includes("hel") // -> false
arrStr[2].includes("hel") // -> false
arrStr[3].includes("hel") // -> cannot read property 'includes' of undefined
If you look at the DCR's answers you will see how to manage the incrementation
both work just fine! It's likely that your i counter is wrong.
var comments=['try a little harder','NEW ENTRY',"another test"];
console.log(comments[1].includes("NEW ENTRY"));
var i = 0;
while ((comments[i].includes("NEW ENTRY")) == false) {
console.log(comments[i]);
i++;}
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
For some reason I'm getting a parse error when trying to send a post request to the server
$.post("../php/user_handler.php", formData, function(data) {
var result = JSON.parse(data);
if(result.status === 'error') {
$('#' + result.control + '-error').html(result.message).css('display', 'inline-block');
} else {
$('#form-message').html(result.message).css('display', 'inline-block');
}
});
The message I'm getting implies that the error is with the syntax of the first character of the first line, but I really don't understand how; I've checked it against several examples of how to make this request and it looks just fine to me.
Simply means that your string is not JSON. First character has to be "{" or "[" but it is not. Might be empty or start with something else. Dump the thing aout on the console.log before you try to parse it.Might help ;)
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 4 years ago.
Improve this question
"addresses" is an array of objects, each object element is having specific _id.
I'm trying to find .indexOf(req.params.a_id) within idsArray (which is an array of ids of all those object elements within the array), but .indexOf() returns -1 although _id exists in idsArray.
code snapshot!
I think .indexOf is most used in strings, you can get it by this way :
idsArray.filter(x => x.id == req.params.a_id)
this will return an array with the matching element.
reference: https://www.w3schools.com/jsref/jsref_filter.asp
UPDATE:
to find the index you can use
idsArray.findIndex(x=> x == req.params.a_id)
To check if an element exists in an array you can use the some method:
idsArray.some(id => id === req.params.a_id)
which returns true or false if the id exists or not.
Check type of your variables.
Maybe req.params.a_id is string ("1") in your case?
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 5 years ago.
Improve this question
I try to Promisify elasticsearch.client.index, and I get
Uncaught typeerror intermediate value is not a function
at makeNodePromissifedEval
I use blubebird 3.5.0
nodejs 8.1.2
This error sometimes happen when you're not using semicolons.
Since you didn't include your code it's impossible to tell if that's the case but 95% when people ask about this error they're missing semicolons.
Example:
// missing semicolons:
const x = 10
(x => console.log(x))(20)
// TypeError: 10 is not a function
// semicolons present:
const x = 10;
(x => console.log(x))(20);
// works fine
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am trying to write a simple JavaScript statement.
if ($(window).scrollTop() > 400 ) || if (!($(window).scrollTop() + $(window).height() > $(document).height() - 500 )) {
$nav.addClass('show');
}
Basically if user scrolls more than 400 from top and more than 500 from bottom I want to add the class show
To solve a problem like this, you need to do something called "debugging". There are many individual debugging techniques. One basic one is to keep replacing things with smaller pieces, or removing pieces, until the problem goes away, or you get an error you can understand more easily.
With your statement
if ($(window).scrollTop() > 400 ) || if (!($(window).scrollTop() + $(window).height() > $(document).height() - 500 )) {
$nav.addClass('show');
}
you will get an error in the console. Open the console and view the error. (If you don't know what the console is, drop everything you are doing and learn that before you do anything else.) Let's say you can't figure out what the problem is from the error message.
In that case, replace the first item in the if condition with a simple true:
if (true || if (!($(window).scrollTop() + $(window).height() > $(document).height() - 500 )) {
$nav.addClass('show');
}
You will continue to get an error. That tells you that the problem was not in the
($(window).scrollTop() > 400 )
portion of the condition. Let's say that you still can't understand the error message, or figure out what to do about it. So next, replace the second part of the condition with another true:
if (true || if (true)) {
$nav.addClass('show');
}
At this point, you will get a console error message saying:
Uncaught SyntaxError: Unexpected token if
It is very unlikely that the initial if is causing this problem; that's obviously valid JavaScript syntax. So the problem must be the second if inside the condition. You can now jump to the conclusion that you do not need to, indeed must not, place a second if statement inside the condition. Remove it. Your problem is solved, without depending on generous SO people to identify every syntax error in your program, and you can move on and complete your project.