Font size changes according to the number of words

wordCount = {}; theWords = []; allWords = data.match(/\b\w+\b/g); //get all words in the document for(var i = 0; i < allWords.length; i = i + 1){ allWords[i] = allWords[i].toLowerCase(); var word = allWords[i]; if(word.length>5){ if(wordCount[word]){ wordCount[word] = wordCount[word]+1; } else{ wordCount[word] = 1; } } } var theWords = Object.keys(wordCount); // all words over 5 characters var result = ""; for(var i = 0; i < theWords.length; i = i + 1){ result = result + " " + theWords[i]; $("theWords.eq[i]").css("fontSize" , (wordCount.length + 50) + 'px'); } return result; } 

I'm having problems with the syntax of the string "$ (" theWords [i] ....... "

I understand how simple the question is, not academic for the community, but I have been looking for this syntax for some time and cannot find any specific forum to fix my syntax error.

I am trying to change the font size depending on how many times the word appears in the document.
The word Count = count will appear.
theWords = all words to which I would like to apply the rule

+5
source share
1 answer

I manage to work something with what you did, using a bit more jQuery to create a list of words to display. hope this helps: D.

 $(document).ready(function() { var data = $(".sometext").text(); wordCount = {}; theWords = []; allWords = data.match(/\b\w+\b/g); //get all words in the document for (var i = 0; i < allWords.length; i++){ allWords[i] = allWords[i].toLowerCase(); var word = allWords[i]; if (word.length > 5) { if (wordCount[word]) { wordCount[word] = wordCount[word] + 1; } else { wordCount[word] = 1; } } } var theWords = Object.keys(wordCount); // all words over 5 characters for(var i = 0; i < theWords.length; i = i + 1) { $('<span/>', { 'text': theWords[i] + " ", 'class': theWords[i] }).appendTo('.result'); } for(var i = 0; i < theWords.length; i++) { $("." + theWords[i]).css("font-size", 15 + wordCount[theWords[i]]*5 + "px"); } }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <p class="sometext">javascript is a language that could be a language without such things as language but not without things as parenthesis. language is the bigest word here.</p> <hr> <div class="result"></div> 
0
source

Source: https://habr.com/ru/post/1244987/


All Articles