Using pure Javascript, let's say hypothetically you prompt on the web page 3 times. With each prompt storing to an array.
var prompts = [];
(function(){
for (var i=0; i<3; i++) {
prompts.push(prompt("What is your favorite color?"))
}
//...
}());
Then you would want a method to loop through each response and determine the "matching" words used.
function collateWords () {
// join all the colors
var sWords = prompts.join(" ")
.toLowerCase().trim().replace(/[,;.]/g,'')
.split(/[\s\/]+/g).sort();
var iWordsCount = sWords.length; // count w/ duplicates
var counts = {}; // object for math
for (var i=0; i<iWordsCount; i++) {
var sWord = sWords[i];
counts[sWord] = counts[sWord] || 0;
counts[sWord]++;
}
var arr = []; // an array of objects to return
for (sWord in counts) {
arr.push({
text: sWord,
frequency: counts[sWord]
});
}
// [sort array by descending frequency|http://stackoverflow.com/a/8837505]
return arr.sort(function(a,b){
return (a.frequency > b.frequency) ?
-1 : ((a.frequency < b.frequency) ? 1 : 0);
});
};
Call the new method and render to page.
//...
var collected = collateWords();
var iWordsCount = collected.length; // count w/o duplicates
for (var i=0; i<iWordsCount; i++) {
var word = collected[i];
document.write(word.frequency + ", " + word.text);
}
//...
Full example http://jsfiddle.net/jdgiotta/n26j5xf0/