• We just launched and are currently in beta. Join us as we build and grow the community.

Dictionary Application using JavaScript and API Source Code Free Download

Redson1

Clutch Master
R Rep
0
0
0
Rep
0
R Vouches
0
0
0
Vouches
0
Posts
66
Likes
49
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 400 XP
This simple project is a Dictionary Application. It is a web-based application that allows users to search for word definitions. This project was mainly developed using Pure JavaScript and Dictionary API. It has a simple and pleasant user interface using a Custom Stylesheet (CSS) script for the design of the page layout. This Dictionary Application is easy-to-use.

How does this Dictionary Application work?

This Dictionary Application is a straightforward application that provides the searched word definitions as the primary purpose. The application is using a Free Dictionary API (https://dictionaryapi.dev/). The users can simply enter the word they wanted to check and upon submitting the form or clicking the Search Button, the result will be queried from the API using JavaScript Fetch API and return the different definitions of the word in every part of speech of a searched word. The result wrapper panel also includes or contains the search word and its phonetic. In case the search word does not have any phonetic, the phonetic text field will be shown blank and if the searched word is unrecognized by the Dictionary API, the application will return a dialog message or box that says "The word entered is Unknown".

Features and functionalities

This project contains the following features and functionalities:

  • Search Word Form
  • Search Word Result Wrapper
  • Display the first list item result of the word FROM Dictionary API
  • Display the different definitions in each word's part of speech (noun, verb, etc.)

Technologies

This Dictionary Application was developed using the following technologies:


How does the Free Dictionary API work or be implemented?

Here's the JS code I used for getting the searched word definitions and other details using JS Fetch API and Free Dictionary API.

  1. // Form Selector
  2. const

    form =

    document.getElementById

    (

    'search-word-form'

    )
  3. // result wrapper selector
  4. const

    resultWrapper =

    document.getElementById

    (

    'result-wrapper'

    )

  5. //Result word and phonetic element
  6. const

    result =

    document.createElement

    (

    'div'

    )
  7. result.id

    =

    'result'
  8. result.innerHTML

    =

    `<

    h3 id=

    "result-word-text"

    ></

    h3>
  9. <

    h5 id=

    "result-word-phonetic"

    ></

    h5>
  10. <

    hr>

    `;

  11. // https://dictionaryapi.dev/ API for dictionary
  12. const

    dictAPI =

    `https:

    //api.dictionaryapi.dev/api/v2/entries/en/`

  13. // Search Word
  14. form.addEventListener

    (

    'submit'

    ,

    function

    (

    e)

    {
  15. e.preventDefault

    (

    )
  16. // get the search word
  17. var

    search =

    document.getElementById

    (

    'search-word'

    )

    .value
  18. // join search word to dictionary API URL
  19. var

    apiURL =

    `${

    dictAPI}

    ${

    search}

    `

  20. // Get word deails
  21. fetch(

    apiURL)
  22. .then

    (

    response =>

    {
  23. // return response data as JSON
  24. return

    response.json

    (

    )
  25. }

    )
  26. .then

    (

    data =>

    {
  27. // search word recognized

  28. // update result wrapper to empty temporarily
  29. resultWrapper.innerHTML

    =

    ``
  30. // Clone result elements
  31. var

    res =

    result.cloneNode

    (

    true

    )
  32. // display searched word
  33. res.querySelector

    (

    '#result-word-text'

    )

    .innerText

    =

    data[

    0

    ]

    .word

  34. // display searched word phonetic
  35. if

    (

    !!

    data[

    0

    ]

    .phonetic

    )

    {
  36. res.querySelector

    (

    '#result-word-phonetic'

    )

    .innerText

    =

    data[

    0

    ]

    .phonetic
  37. }

    else

    {
  38. if

    (

    !!

    data[

    0

    ]

    .phonetics

    )

    {
  39. Object

    .values

    (

    data[

    0

    ]

    .phonetics

    )

    .map

    (

    phonetic=>

    {
  40. if

    (

    !!

    phonetic.text

    )

    {
  41. res.querySelector

    (

    '#result-word-phonetic'

    )

    .innerText

    =

    phonetic.text
  42. return

    false

    ;
  43. }
  44. }

    )
  45. }
  46. }
  47. Object

    .values

    (

    data[

    0

    ]

    .meanings

    )

    .map

    (

    meaning =>

    {
  48. var

    meanings =

    ``
  49. // display searched word part of speech
  50. meanings =

    `<

    h5 class

    =

    "partOfSpeech"

    >

    ${

    meaning.partOfSpeech

    }

    </

    h5>

    `
  51. Object

    .values

    (

    meaning.definitions

    )

    .map

    (

    definition =>

    {
  52. // display searched word meaning
  53. meanings+=

    `<

    p class

    =

    "meaning"

    >

    ${

    definition.definition

    }

    </

    p>

    `
  54. }

    )
  55. res.innerHTML

    +=

    `<

    div class

    =

    "result-item"

    >

    ${

    meanings}

    </

    div>

    `
  56. }

    )
  57. //updating the result wrapper with the actual result
  58. resultWrapper.appendChild

    (

    res)
  59. }

    )
  60. .catch

    (

    err=>

    {
  61. // show dialog box if entered or searched word in unknown
  62. alert(

    "The word entered is Unknown."

    )
  63. console.error

    (

    err)
  64. }

    )
  65. }

    )

Snapshots

Here are some snapshots of this Dictionary APP page layout and examples.

Page UI

Search Word Form

Search Word Result

Example #1

Example #2

The Dictionary Application complete source code zip file is available on this website and it is free to download. Feel free and modify the source code to do some experiments or to enhance the application. This simple project was mainly developed for educational purposes only.

How to Run?

  1. Download the provided source code zip file. (download button is located below)
  2. Extract the downloaded source code zip file.
  3. Locate the index.html file in the extracted source code directory.
  4. Browse the index file with your preferred browser.

DEMO VIDEO

That's it! I hope this Dictionary Application using JavaScript and Free Dictionary API Source Code will help you with what you are looking for and will be useful for your current and future web application projects.

Explore more on this website for more Tutorials and Free Source Codes.

Enjoy Coding =)

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.

2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.


Download
You must upgrade your account or reply in the thread to view hidden text.
 

451,993

323,299

323,308

Top