html
html
1
2
3
4
5
6
7
8
9
10
11
12
<!DOCTYPE html>
<html>
<head>
<title>Counting frequency of text in list item content</title>
</head>
<body>
<h5>List with random content:</h5>
<ul id="theList"></ul>
<h5>List item frequency counter:</h5>
<div id="output"></div>
</body>
</html>
Enter to Rename, Shift+Enter to Preview
css
css
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
body
{
margin: 0;
padding: 2%;
background: #a55407;
color: #f8f8f8;
font-size: 0.75em;
}
#theList
{
height: 35vh;
max-height: 35vh;
overflow-y: scroll;
}
#output
{
background: #eee;
color: #808080;
padding: 2%;
height: 35vh;
overflow-y: scroll;
}
#output p
{
font-weight: bold;
Enter to Rename, Shift+Enter to Preview
js
js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
window.onload = () =>
{
const subjects = [ "Algorithm", "Android App Development", "CSS Animation", "Bug Bounty", "Cryptography", "Databases", "Data Recovery", "Data Science", "Data Structure", "Digital Forensics", "Graphic Design", "Internet of Things", "Media Services", "Network Security", "Web Development", "Web Services", "Web Security" ];
const subjectCount = subjects.length;
const freq = {};
// generate list items with randomly selected text from <subjects>
for( let i = 0, index = null; i < 200; i++ )
{
if( index )
{
let last_index = index;
do
{
index = Math.floor( Math.random() * subjectCount )
} while( index == last_index);
}
else
{
index = Math.floor( Math.random() * subjectCount );
}
const text = subjects[ index ];
const item = document.createElement( "li" );
item.textContent = text;
theList.appendChild( item );
if( text in freq )
{
Enter to Rename, Shift+Enter to Preview
BROWSER
Console
Run