Displaying the characters and their frequency pls help me for project only :) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Displaying the characters and their frequency pls help me for project only :)

<!DOCTYPE HTML> <html> <body> <p>Click the button to Decompress.</p> <button onclick="myFunction()">Try it</button> <br/> <br/>Enter Text: <input type="text" id="txt1" name="text1"> <p id="demo"></p> <p id ="demo2"></p> <br> <button onClick="getFrequency(string)"> Show the Characters</button> <script> function myFunction() { var y = document.getElementById("txt1").value; document.getElementById("demo").innerHTML = y.length*8; } //function for displaying the frequency of the characters function getFrequency(string) { var x = document.getElementById("txt1").value; document.getElementById("demo2").innerHTML = freq; var freq ={} for (var i=0; i<x.length;i++) { var character = x.charAt(i); if (freq[character]) { freq[character]++; } else { freq[character] = 1; } } return freq; } </script> </body> </html>

15th Dec 2016, 2:27 AM
Mike Edrian
Mike Edrian - avatar
1 Answer
+ 4
See the code in the following link. https://code.sololearn.com/WWXyA9G445xP/#
23rd May 2019, 4:18 PM
r1c5
r1c5 - avatar