Simple Web Dictionary | JavaScript Switch Statement Project

Here, we are going to learn about the switch statement in JavaScript with a project that is simple web dictionary.
Submitted by Godwill Tetah, on June 23, 2019

Hi! At times, beginners always find it hard getting the application of the theory they learn in programming or a particular language.

In this article, we'll look at another application of JavaScript. We'll see the use/application of the switch statement which will help us build a simple web dictionary app.

I called it a web dictionary app because the switch statement gives us the opportunity to program different outputs when different requests are made.

The application will get user input via a form and will output the result as an alert.

It equally has an assigned default value if no result is found.

First of all, let's begin by revising the syntax of the switch statement.

The switch statement is used to avoid writing several if...else statements.

    switch(expression) {
        case a:
            code block

        case b:
            code block

            code block

Therefore, it evaluates different entries(case) and checks for its specific output, else it displays the default value.

Open a text editor and type the code below.

Save the file with the name Web Dictionary.html

In this project, I added just some few test word in the switch case.

Every acronym has it's meaning registered in the switch statement and a default value has been set for a case with no results.

NB: You can still use your desired CSS style!

<!DOCTYPE html>
        <script type="text/javascript">
            function Dic() {
                var Word = document.getElementById("word").value;
                var w = document.getElementById("go").value;
                switch (Word) {
                    case "PDF":
                        alert("portable digital format");
                    case "ASCII":
                        alert("american standard code for information interchange");
                    case "SIM":
                        alert("subscriber identity module");
                    case "HTML":
                        alert("hypertext markup language");
                    case "PHP":
                        alert("hypertext preprocessor");
                    case "CSS":
                        alert("cascading style sheet");
                    case "MTN":
                        alert("Mobile telephone network");
                    case "ISP":
                        alert("internet service provider");
                    case "DSL":
                        alert("digital subscriber line");
                        alert("Thanks for trusting us! No match found!");
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>C.P.O TOOLS</title>
        <meta name="description" content="Good coders code, great coders reuse." />

        <meta name="viewport" content="width=device-width, initial-scale=1" />

        <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
        <link rel="icon" href="favicon.ico" type="image/x-icon" />

        <link rel="stylesheet" type="text/css" href="css/reset.css" />
        <link rel="stylesheet" type="text/css" href="css/style-index.css" />

        <div id="wrapper">
            <div id="top">
                <div id="logo">
                    <a href=""><img src="images/logo.png" alt=" logo" title="Tools For All" /></a>
                <div id="logo-text">
                    Tools For All

        <div id="body">

            <div id="text">
                Good coders code, great coders reuse.
            <hr />
            Free Computer Acronym (Abbreviation) Dictionary!!
            <p>Test Acronyms include...</p>
            <br />
            PDF <br />
            MTN <br />
            DSL <br />
            SIM <br />

                <br />
                <input type="text" id="word" size="30" required placeholder="Word" />
                <br />
                <br />
                <button onclick="Dic2();" id="go">Search!</button>

            <br />
            <br />

            <hr />

Output Image:

Simple web dictionary project using JS

Thanks for coding with me. Your comments are most welcome.

JavaScript Examples »

Related Examples

All JavaScript Examples

Comments and Discussions!

Load comments ↻

Copyright © 2024 All rights reserved.