In my experiment, I want to compare participants’ input (stored in a var called text.text) to correct answer (stored in a var called final_words), and return matched words in an array called matched_words.
text.text is an array of letters, whereas final_words is an array of words. When I ran my experiment online, I get this TypeError: text.text.join is not a function
Below is my JavaScript code relating to this issue
for (let word of final_word) {
if(text.text.join("").toLowerCase().contains(word)) {
matched_words.push(word);
}
}
I looked at my data file and text.text column only has the words, not quotations around letters. How should I change the code if it wasn’t array, I’m actually not sure what data type it is.
My best guess would be that text.text is a string, could you try the following?
// Divide input into words
const wordsOfText = text.text.split(' ');
for (let word of wordsOfText) {
if (final_words.includes(word)) {
matched_words.push(word);
}
}