Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    GIF shows where to locate </> in the thread and or post editor toolbar.
    To learn more about how to use our BBCode feature, review our "How to post your code into threads" here.

    Thank you, Code Forum.

JavaScript JQuery troubleshooting - needed advise and hint

Kana

New Coder
Hi all,

Being frankly, the issue I am encountering with the code below is a bit strange, and as a result I stuck with. To figure out it, I am writing my question here and hope someone is avaiable to help me with. I just need advise and hint what wrong with the code is.

I appreciate your feedbacks.

Kind regards,
Kanu

The code:
Code:
<!DOCTYPE html>
<html lang="en">
<head>
        <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
       <title> To solve - JQuery </title>
        <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM" crossorigin="anonymous">
        <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.13.2/themes/smoothness/jquery-ui.css">
</head>
<body class="bg-dark">
        <main class="text-success">
                  <h1>has time to solve JQuery </h1>
                 <hr class="text-light bg-light" />
                <section class="text-light mt-5 ">
                        <div class="out_box">
                                <div class="inner_box">
                                        <form  id="form_aka">
                                                <legend class="text-light mx-auto p-2">Your text here:</legend>
                                                <textarea cols="70" rows="10" id="input_aka" class="text-dark rounded-4">
                                                </textarea>
                                                <br />
                                                <button class="btn btn-outline-info rounded">Convert</button>
                                        </form>
                                </div>
                         `   </div>
                                
                        <div class="out_box2 border border-light w-50 h-25 rounded-4">
                                <div class="inner_box2">
                                        <div id="output_aka"></div>
                                </div>
                        </div>
                </section>
        </main>

        <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-geWF76RCwLtnZ8qwWowPQNguL3RmwHVBC9FhGdlKrxdiJJigb/j/68SIy3Te4Bkz" crossorigin="anonymous"></script>
        <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.13.2/jquery-ui.min.js"></script><script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.0/jquery.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-easy-loading/1.3.0/jquery.loading.min.js" integrity="sha512-tKLMM/v1nsieFOgUyeMSC2jdB4UtbU7R88e+S0pVIz3f6sWdpOpirG2j5pulmH45l1vk47J84V4ifXAYv+wuMw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<!--  CODE -->
        <script>
            $(document).ready(function(){
                "use strict";
                  
                 const alphabet = {
                             'Alphabet': {"A":1, "B":2,  "C":3, "D":4, "E":5 },
                            "Number": {1:"A", 2:"B", 3:"C", 4:"D", 5:"E"}
                  };
                
                var msg = "";
                 const  strm_dspl = $("#output_aka");
                var render_me = $("#input_aka").val();

                const tst = function(){
                    $("#form_aka").on("submit",  function(event){
                        event.preventDefault();
                      
                        strm_dspl.text( () => {
                            $.each(render_me.toUpperCase(), (val) => {
                                console.log( val);                                     
                                if (val in alphabet.Alphabet) {        // .contains()  through an error
                                    console.log(alphabet.Alphabet[val]);   
                                } else if (val in alphabet.Number) {
                                    console.log(alphabet.Number[val]);
                                }  else {
                                    console.log("I did not get this strangeness on my laptop");
                                }
                            })
                         }).css({"color": "snow", "padding": "10px"});
                        
                        console.log("I am a value to display:",  $("#input_aka").val());
                        // Emtpy textarea after submitting
                         render_me = "";
                        } );
                    }
                 // Call function
                tst();
            });
        </script>
</body>
</html>
 
Thank you for the feedback. Not everyone on this site does that.
The root cause llied in
JavaScript:
strm_dspl.text( () => { // codes..... )
. Here is the correction.
JavaScript:
$(document).ready(function(){
    "use strict";

    const alphabet = {
        'Alphabet': {"A":1, "B":2,  "C":3, "D":4, "E":5 },
        "Number": {1:"A", 2:"B", 3:"C", 4:"D", 5:"E"}
    };

    const  strm_dspl = $("#output_aka");

    $("#form_aka").on("submit",  function(event){       
        var render_me = $("#input_aka").val();
        event.preventDefault();
//        var msg = "";
        render_me.toUpperCase().split('').forEach((a)=> {
            console.log(a);
            if (a in alphabet.Alphabet) {        // .contains()  through an error
                console.log(alphabet.Alphabet[a]);
                //msg += alphabet.Alphabet[a];
            } else if (a in alphabet.Number) {
                console.log(alphabet.Number[a]);
                //msg += alphabet.Number[a];
            }  else {
                console.log("I did not get this strangeness on my laptop");
            }
        })           
        //strm_dspl.text(msg).css({"color": "snow", "padding": "10px"});
        console.log("I am a value to display:",  $("#input_aka").val());
        // Emtpy textarea after submitting
        render_me = "";
    });
});

P.S. if there is a syntax error like closing brackets, parentheses or curly brackets is missing, know that I have not copied and pasted the code. Just typed to provide the answer I got. 🙂

KInd regards,
 

Buy us a coffee!

Buy me a coffee.
Back
Top Bottom