This time item === target.

 
Gastello: Yesterday someone guided me to use console. var item = do***ent.getElementById”VALIDATE_STU_CREDENTIALS1″;

Gastello: Those were to the first two commands out of the 4. now i can see those in the console.

Gastello: But then how to did he findout that it is to be clicked?

Keitsock: What do you mean smgs

Gastello: He told how to use console. . i am trying to figure out.

Keitsock: Ok. and what is your question exactly?

Lostracco: Keitsock does this function make complete sense to you as what and how it works? http://jsbin.com/tulokuyaro/edit?js,console

Cooperstein: I’m talking about contains functions

Gastello: Keitsock i want to find out whether to submit or click or validate that var item = .

Keitsock: Smgs: no idea, you would have to provide more context

Keitsock: What is the element in question? what are you trying to do?

Gastello: Keitsock, https://jsfiddle.net/xo4kktzy/ Should i submit instead of clicking ?

Keitsock: Still need more context. is this button inside a form?

Keitsock: If you have a form you are trying to submit, I would look up the form node itself and call .submit on that form

Keitsock: However what you have here would also work. it’s just a round-about way of doing it. it’s not clear

Gastello: Would also work. how ?

Keitsock: Well, you are calling .click on a submit button

Keitsock: Which is the same as clicking that submit button

Keitsock: Which will submit the form it’s inside

Keitsock: So I would say the better approach would be to look up the form in question, and call .submit on it instead

Keitsock: AramKaram: yes, though reduce isn’t ideal here because htere’s no way to make it stop executing once you’ve found a match

Keitsock: Which you obviously have sort of worked around with your if check

Keitsock: But it will still continue to execute again and again. so if your array is 1000 items long and it matches in the third element it would still fire 1000 times

Givant: Ah damn! then why is this even in underscore? why would they even design such a faulty function in a first place lol :-/

Gastello: Form . /form Keitsock right ?

Fabbri: I have no clue how that function contains work. I dont see how it iterates or how wasFound variable ever turns to be true. this is kinda hard to think of, especially for me :-/

Keitsock: Smgs: yes that’s how you make a form

Keitsock: Smgs: p is not a form, no

Keitsock: You cannot submit a p tag

Keitsock: AramKaram: ok so you remember the line item invoice example I gave?

Keitsock: For each line, you have two figures. the current running total, and the current line’s total

Keitsock: You perform an operation, which is to add the current line to the running total, then return the running total

Keitsock: Which feeds into the next line

Keitsock: Reduce works like that

Asiedu: Aha, I know that about reduce, but I can’t see how contains use that to do what it does? :-/

Aust: I know reduce uses an ac***ulator and next iterating value to add up together and eventually return ac***elator as a result

Keitsock: Which is your line return item === target;

Keitsock: That value populates wasFound each time around

Keitsock: Until it returns true, at which point your if statement matches, and it will instead “return true;”

Keitsock: So first time through, you check item === target; lets say it returned false

Bembury: Let me read this whole thing again

Keitsock: Now next time through, wasFound is false, the if statement fails the check, and it does another item === target

Keitsock: This time item === target returns true. so we return true, which feeds into the next wasFound