2
I created two arrays, one with questions and the other with answers.
Follows the model.
perguntas[0] = "que sao dinossauros";
respostas[0] = ["Constituem um grupo de diversos animais membros do clado Dinosauria"];
perguntas[1] = "tipos de dinossauros que existiram";
respostas[1] = ["Terópodes, Saurópodes, Ceratopsídeos, Ornitópodes, Estegossauros, Anquilossauros,Paquicefalossauros"];
Well, I need to make sure that I find if certain text, is contained in that array, knowing in what position it found, so I can return a response.
I tried it this way.
if( $.inArray(pergunta, perguntas[i]) !== -1 ){
alert("encontrei");
}else{
alert("não encontrado");
};
So it works, however I need to find which position was found, to send a respective return.
I created a repetition to be able to identify in which position it was found, but never finds the text.
for(var i = 0; i < perguntas.length; i++){
if( $.inArray(pergunta, perguntas[i]) !== -1 ){
alert("encontrei");
}else{
alert("não encontrado");
};
}
Thank you
You are looking for the question, in case, and need to know what is the index of this question in the list?
– Woss
I forgot to put in the remark that the user who enters the question. Then let’s say that the guy type "Tiranosaurus", if he finds the content, I need to know in which information was found
– gabrielfalieri
Ok, so the user type in a word, you want to search what is the question that has this word and get the index of this in the list?
– Woss
I want to check if the word is contained in the array. If it is, I need to know which part is in order to return the corresponding answer.
– gabrielfalieri