JAVASCRIPT tagcloud.html </html> Questions I need help with. Define an external
ID: 3917438 • Letter: J
Question
JAVASCRIPT
tagcloud.html
</html>
Questions I need help with.
Define an external JavaScript file tagcloud.js which contains the following functions:
</html>
Questions I need help with.
Define an external JavaScript file tagcloud.js which contains the following functions:
makeCloud()This function is the event handler for button "Make Cloud". It should- grab the contents of the textarea, a string of tags separated by spaces.
- parse that string into an array of tag strings, sorted by lexicographic ordering. (Remember this array may have repeat tags.)
- Create two arrays: One array contains unique tags and second corresponding array will contain the frequencies of each of those tags.
- The unique tag array and the frequency tag array pair is an example of parallel arrays. If the unique array contains elements apple, banana, cherry in indeces 0, 1 and 2 respectively, then the frequency array will contain elements 5,3,4 (for example) in indices 0,1 and 2. Where 5,3 and 4 are frequencies for apple, banana and cherry respectively.
- keep track of the maximum frequency for the set of tags. (Write a helper function to compute this.)
- create a
divelement containing all the tags asspanelements as described above. (You should write a helper fuction to achieve this.) - use the properties of the DOM address for the
divelement to set a.1em solid silverborder for thediv. Give thediva blue background. a silver foreground color, and an extra large serif font. - loop through all the
spanchild elements (the tags) in thediv(tag cloud) and assign a suitable font size to them. The font size should at least be 15pt. The font size will be determined by taking the frequency at which the tag occurs divided by the max number of occurrences, then the resulting fraction is multiplied by 20. This will give you a decimal number between 0 and 20. Round the number to nearest integer and add 15. Now append the string "pt" and you have a string that is something like "22pt". This string should be used in setting the font-size. (I suggest defining a helper function to do this step.) - Add onclick function to each span element. When you click on the span element it should alert how many times the tag appears. See image below for an example.
- remove the
divelement already belonging totagcloud.htmland replace it with the newdivyou just created. The newdivshould be in the same position in the DOM tree as the olddivwas.
saveCloud()This function is the event handler for button "Save Cloud".loadCloud()This function is the event handler for button "Load Cloud".clearArea()This function is the event handler for button "Clear TextArea".
Explanation / Answer
function makeCloud() { //grabs texarea text, splits into an array, and sorts the array var tags = document.getElementById("tags").value.split(" ").sort(); var uniqueTags = []; var frequencyTags = []; for (var i = 0; iRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.