Final answer:
The calcWordFrequencies function uses JavaScript's prompt() to get input, counts word frequencies with a map, and outputs the results to the console.
Step-by-step explanation:
To write a function calcWordFrequencies that reads a list of words and outputs their frequencies, you would first use the prompt() function in JavaScript to get user input. Then, you would split the input string into words and count the frequency of each word with a map or an object. Here is an example of how to write this function:
function calcWordFrequencies() {
var input = prompt('Enter words separated by spaces:');
var words = input.split(' ');
var frequencyMap = {};
for (var i = 0; i < words.length; i++) {
var word = words[i].toLowerCase();
if (frequencyMap[word]) {
frequencyMap[word]++;
} else {
frequencyMap[word] = 1;
}
}
for (var word in frequencyMap) {
console.log(word + ' ' + frequencyMap[word]);
}
}
// Call the function from the JavaScript console to test
// calcWordFrequencies();
This function iterates over the input words and keeps count of their frequencies in a map. It then logs each word's frequency to the console. Note that it converts all words to lowercase to count them correctly without case sensitivity.