I Have this problem and honestly have no idea where or how to start this, can anyone give me an idea or help?

Write a JavaScript program to calculate the statistics of words in a web page. When running the program in a web page, the script should output all words in descending order of their number of occurrences. The number of occurrences should be displayed along with the words. When two or more words have the same number of occurrences, order them alphabetically. The output should show up as a new web page when the program runs. HTML tags and scripts inside web pages should not be considered as words by the program. The program should run in all web pages, not just one page.

I got python coding for it, but not sure for java, also how to order by descending order

import re

def addWord(token, frequencies):
    count = 0
    word = ''.join(token)
    if word in frequencies:
        count = frequencies[word]
    frequencies[word] = count + 1

def getWordFrequencies(text):
    pattern = re.compile('\w')
    frequencies = {}
    token = []
    
    for c in text:
        if pattern.search(c):
            token.append(c)
        elif token:
            addWord(token, frequencies)
            token = []
    
    if token:
        addWord(token, frequencies)

    return frequencies



wordCount = raw_input("Please Enter text here: ")

result = getWordFrequencies(wordCount)

for word, freq in result.iteritems():
    print freq, "\t", word

Java and javascript are not the same languages.

sorry but it needs to be in javascript didnt see a javascript forum just seen java and posted

you should have thought and looked better before you posted.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.