6 Replies - 549 Views - Last Post: 25 January 2013 - 01:56 PM

#1 jmallen  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 25-January 13

Project Help Please

Posted 25 January 2013 - 12:26 PM

Hello, I am attempting to create a spell checker using javascript. I am new but I have experience.

I am not using a dictionary, instead I want to use an array to hold 6 or 7 words that are spelled correctly.

The user will enter one of the words in a text box and hit a button (labeled spell check of course).

I am assuming I am going to want to use an on-click event for the button that will compare the word submitted in the textbox to one of the 6 or 7 words in the array.

I have the html and css done. I have also created the array.

I am not sure how I would compare the string that is inputted by the user to my wordlist array. I need help please.

This should (in theory) create a spell checker that will check the words in my array.

//wordlist array declared and populated
        var wordlist = new Array(6);
            wordlist[0] = "dog";
            wordlist[1] = "potato";
            wordlist[2] = "napkin";
            wordlist[3] = "knife";
            wordlist[4] = "pumpkin";
            wordlist[5] = "probably";
            wordlist[6] = "wednesday";


Is This A Good Question/Topic? 0
  • +

Replies To: Project Help Please

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 2876
  • View blog
  • Posts: 9,544
  • Joined: 12-December 12

Re: Project Help Please

Posted 25 January 2013 - 12:47 PM

The array.indexOf() method will tell you whether a word exists in the array. MDN

However, it will look for an exact match. You could take a (very) simple approach and maintain another larger array which contains a list of all the common mis-spellings of the words in the first array.

Otherwise you will need to investigate fuzzy searching. There are probably JS modules (perhaps via jQuery) that you can use to do this. Otherwise, it will be quite a challenge to build such as system yourself.

Try this fuzzy search perhaps.

This post has been edited by andrewsw: 25 January 2013 - 12:45 PM

Was This Post Helpful? 1
  • +
  • -

#3 jmallen  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 25-January 13

Re: Project Help Please

Posted 25 January 2013 - 12:53 PM

Thank you for the advice. That brings me to some new questions. What are my other options(while using an array of 6/7 words for a dictionary) to allow a user to check the spelling of a word that they typed? It does not have to be in a text box. I am unsure if there is a simpler solution. I just want to make a 6/7 word array to use as a dictionary. Then create some form of a spell checker that the user can enter those words and see if they typed them correctly.

I am thinking of using an if statement for outputting correct or incorrect spelling. If the word is correct then output word is spelled correctly. Else the word is incorrectly spelled.

This post has been edited by Dormilich: 25 January 2013 - 01:41 PM
Reason for edit:: removed unnecessary quote

Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 2876
  • View blog
  • Posts: 9,544
  • Joined: 12-December 12

Re: Project Help Please

Posted 25 January 2013 - 01:07 PM

I've mentioned the two options that I am aware of and, yes, both require the use of if statements and loops (to loop through the array(s)).

A possibility is to use Ajax calls to retrieve details from an online dictionary (or fuzzy-match feature) but this is really just an extension of the use of arrays; that is, the retrieved data would probably be stored in another array. This is not necessary, though, if you are only using 6 or 7 words.

As a starting point I would create another array with 20 or so misspellings of the words you are checking. (Hint: make everything lower or uppercase.)
Was This Post Helpful? 1
  • +
  • -

#5 jmallen  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 25-January 13

Re: Project Help Please

Posted 25 January 2013 - 01:22 PM

Alright I see what you mean now. I did not think this would be that difficult. I am trying to complete an exercise from a book I found. I like the idea of creating a spell checker and I wanted to make mine similar. Any incite on the original exercise?
This is the original exercise:


(Project: A Spell Checker) Many popular word-processing software packages have built-in
spell checkers.
In this project, you are asked to develop your own spell-checker utility. We make suggestions
to help get you started. You should then consider adding more capabilities. Use a computerized
dictionary (if you have access to one) as a source of words.
Why do we type so many words with incorrect spellings? In some cases, it is because we simply
do not know the correct spelling, so we make a best guess. In some cases, it is because we transpose
two letters (e.g., “defualt” instead of “default”). Sometimes we double-type a letter accidentally (e.g., “hanndy” instead of “handy”). Sometimes we type a nearby key instead of the
one we intended (e.g., “biryhday” instead of “birthday”). And so on.
Design and implement a spell-checker application in Javascript. Your program should maintain
an array wordList of strings. Enable the user to enter these strings.
Your program should ask a user to enter a word. The program should then look up the word
in the wordList array. If the word is present in the array, your program should print “Word is
spelled correctly.”

If the word is not present in the array, your program should print “word is not spelled correctly.”
Then your program should try to locate other words in wordList that might be the word
the user intended to type. For example, you can try all possible single transpositions of adjacent letters
to discover that the word “default” is a direct match to a word in wordList. Of course, this
implies that your program will check all other single transpositions, such as “edfault,” “dfeault,”

“deafult,” “defalut” and “defautl.”When you find a new word that matches one in wordList, print
that word in a message, such as “Did you mean "default?"”
Implement other tests, such as replacing each double letter with a single letter and any other
tests you can develop, to improve the value of your spell checker.

This post has been edited by Dormilich: 25 January 2013 - 01:41 PM
Reason for edit:: removed unnecessary quote

Was This Post Helpful? 0
  • +
  • -

#6 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 2876
  • View blog
  • Posts: 9,544
  • Joined: 12-December 12

Re: Project Help Please

Posted 25 January 2013 - 01:33 PM

That exercise is quite clear in what it is asking you to do. It reads to me as though it wants you to transpose letters, and perform other transformations, of the words that they enter and keep looking to see if these new words match the correctly spelt words in your single array - rather than having a second array containing common misspellings, as I mentioned.
Was This Post Helpful? 1
  • +
  • -

#7 jmallen  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 25-January 13

Re: Project Help Please

Posted 25 January 2013 - 01:56 PM

View Postandrewsw, on 25 January 2013 - 01:33 PM, said:

That exercise is quite clear in what it is asking you to do. It reads to me as though it wants you to transpose letters, and perform other transformations, of the words that they enter and keep looking to see if these new words match the correctly spelt words in your single array - rather than having a second array containing common misspellings, as I mentioned.



So then the user would be typing in a textbox. I am unsure how to compare what the user enters to my array. I looked at transposing strings, its not really making sense. I am going to continue looking.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1