3.12 LAB: JavaScript Arrays
Implement the function calcWordFrequencies() that uses a single prompt to read a list of words (separated by spaces). Then, the function outputs those words and their frequencies to the console.
Ex: If the prompt input is:
hey hi Mark hi mark
the console output is:
hey 1 hi 2 Mark 1 hi 2 mark 1
Note: To test the JavaScript locally, call the calcWordFrequencies() function from the JavaScript console in the browser.
The javascript function ,calcWordFrequencies that prompts user
to enter the word list and split by space.Then user the array to
count the frequency of each word in the words list. Then show the
word and its corresponding frequency count to console
output.
Save the below file as frequency.html
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function calcWordFrequencies()
{
let words = prompt("Enter word list ").split(" ");
let frequency =
{};
for (var i = 0; i < words.length; i++) {
if (!frequency[words[i]]) {
frequency[words[i]]=1;
} else {
frequency[words[i]]++;
}
}
for (var i = 0; i < words.length; i++) {
console.log(words[i]+ " " +frequency[words[i]]);
}
}
calcWordFrequencies();
</script>
</head>
<body>
</body></html>
Sample Output:


3.12 LAB: JavaScript Arrays Implement the function calcWordFrequencies() that uses a single prompt to read a...
<!DOCTYPE HTML>
<html lang="en">
<title>JavaScript Array Lab</title>
<script src="script.js"></script>
<body>
<p>To test your function,
call divideArray()
from the JavaScript console in the browser.</p>
</body>
</html>
Don't edit your code on the above code and do not copy from
others', plz!
// Put your solution here in script.js
Write the function divideArray() in script.js that has a single numbers parameter containing an array of integers. The function should divide numbers into two arrays, evenNums for...
C++ please! (1) Prompt the user to enter the name of the input file. The file will contain a text on a single line. Store the text in a string. Output the string. Ex: Enter file name: input1.txt File content: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. Nothing ends here; our hopes and our journeys continue! (2) Implement a PrintMenu() function,...
C++ (1) Prompt the user to enter a string of their choosing (Hint: you will need to call the getline() function to read a string consisting of white spaces.) Store the text in a string. Output the string. (1 pt) Ex: Enter a sample text: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. Nothing ends here; our hopes and our journeys continue!...
6.17.1 Lab #5 - Chapter 6 Text analyzer & modifier (C) (1) Prompt the user to enter a string of their choosing. Output the string. (1 pt) Ex: Enter a sentence or phrase: The only thing we have to fear is fear itself. You entered: The only thing we have to fear is fear itself. (2) Complete the GetNumOfCharacters() function, which returns the number of characters in the user's string. We encourage you to use a for loop in this...
Python 9.13 LAB: Warm up: Parsing strings (1) Prompt the user for a string that contains two strings separated by a comma. (1 pt) Examples of strings that can be accepted: Jill, Allen Jill , Allen Jill,Allen Ex: Enter input string: Jill, Allen (2) Report an error if the input string does not contain a comma. Continue to prompt until a valid string is entered. Note: If the input contains a comma, then assume that the input also contains two...
in c++ please
tortViewHistory Bookmarks Window Help learn Tybooks.com 3.12. LAB: Exact change functions My Ibrary > CS 010: Introduction To Computer Science for Science, Mathematics & Engin. 8.12: LAB: Exact change - functions zyBooks catalog Help/FAQ Stephanie R Write a program with total change amount as an integer input that outputs the change using the fewest coins, one coin type per line. The coin types are dollars, quarters, dimes, nickels, and pennies. Use singular and plural coin names as...
(1) Prompt the user to enter a string of their choosing. Store the text in a string. Output the string. (1 pt) Ex: Enter a sample text: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. Nothing ends here; our hopes and our journeys continue! You entered: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews...
11.9 Week 11 Lab: 2D Arrays For this lab, you only need to write a single user-defined function that analyzes a 2D array of chars. You do NOT need to write any of the code in main0 that calls your function. Make sure to use the template and only add code to the user-defined function. Write a function win0 with the following definition (i.e. prototype): int win(char board17)15), char player) The function win0 should return a 1 if the character...
5.19 Lab 11b: Soccer team roster Instructor note: NOTE Unlike our other assignments, this one has only two programs: People's Weights and this one. To earn 30 points, you must do both assignments. Allow ample time to complete them Passing arrays to methods Review Chapter 6.8 Array Parameters if you wish to use methods in your program (a good idea). Since we pass a reference to the array's location in memory, changes made to the array within the method will...