Question

JavaScript When the button is pressed, the application should prompt the user to enter a string...

JavaScript
When the button is pressed, the application should prompt the user to enter a string or ‘***’ to quit, and then remove all instances of the following substring “erd” in the input string. Assume no spaces in the string. Make the entire string lowercase to start with.
It should show the parsed string (with the words already removed) in the text area.
The application should then again do the above, clearing out the text area before each iteration of your loop, until the user enters ‘***’. It should then alert
‘Thanks for using the text parser’ and exit.   

Homework Answers

Answer #1

In the following program, the page reloads after entering '***' and alerting the user. You can do anything like redirecting to another page instead of reloading the page.

HTML code + Javascript:

<html>
    <head>
        <title>
            Text Parser
        </title>
        <style>
            h2{
                margin-top: 100px;
                text-align: center;
            }
            .play_area{
                padding:30px;
                text-align: center;
            }
            .my_btn{
                width:100px;
                text-align: center;
                margin: auto;
                margin-top:30px;
                padding:10px;
                background-color: rgb(0, 92, 128);
                cursor: pointer;
                color:white;
                font-weight: bold;
            }
            .my_btn:hover{
                background-color: rgb(9, 117, 180);
            }

            #showstring{
                padding:10px;
            }
            .info, .result{
                text-align: left;
                padding:10px;
                background-color: rgb(224, 221, 221);
                width:49%;
                margin:auto;
            }
        </style>
    </head>
    <body>
       <h2>Text Parser</h2> 
       <div class="play_area">
           <div class="result">Result</div>
           <textarea name="showtext" id="showstring" cols="100" rows="5"></textarea>
           <div class="info">Click the button to enter the string</div>
           <div class="my_btn" onclick="takeInput()">Click</div>
       </div>
       <script>


           //function to prompt user for input string
           function takeInput(){

                //clearing the textarea
                document.querySelector("#showstring").value = "";
                var input = prompt("Enter a string or '***' to quit");

                //if input is '***'
                if(input === '***'){
                    alert("Thanks for using the text parser");

                    //just reloading the page
                    //you can redirect to any page after exitting
                    location.reload();
                }
                else{

                    //convert string to lowercase
                    input = input.toLowerCase();

                    //removing all instances of 'erd'
                    var result = input.replaceAll("erd", "");

                    //showing the modified string in textarea
                    document.querySelector("#showstring").value = result;
                }
           }
       </script>
    </body>
</html>

Output:

if you have any doubt, do share in comments section!

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
This is C. Please write it C. 1) Prompt the user to enter a string of...
This is C. Please write it C. 1) Prompt the user to enter a string of their choosing. Store the text in a string. Output the string. (1 pt) Ex: Enter a sample text: we'll continue our quest in space. there will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. nothing ends here; our hopes and our journeys continue! You entered: we'll continue our quest in space. there will be...
Need this done using PHP code and not javascript Create a PHP form with a textarea...
Need this done using PHP code and not javascript Create a PHP form with a textarea field input and a submit button. The textarea field should be able to accept up to 250 characters. When the user clicks the Submit button, read the text in the textarea and display the following results on a web age. At the bottom of the page include a link back to the form. Number of characters: Number of words: (hint: explode the string into...
Program Behavior Each time your program is run, it will prompt the user to enter the...
Program Behavior Each time your program is run, it will prompt the user to enter the name of an input file to analyze. It will then read and analyze the contents of the input file, then print the results. Here is a sample run of the program. User input is shown in red. Let's analyze some text! Enter file name: sample.txt Number of lines: 21 Number of words: 184 Number of long words: 49 Number of sentences: 14 Number of...