Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello, I am having some difficulty figuring out these problems and I could use s

ID: 3752380 • Letter: H

Question

Hello, I am having some difficulty figuring out these problems and I could use some help! We are writing the code in Javascript and have to display the answers in an Li inside of a Ul in this format. Here is the code for the robot.html and a picture of the assignment description.

<!DOCTYPE html>

<!-- Do not edit this file, only submit your robot.js -->

<html>

<head>

    <meta charset="utf-8">

    <title>Homework 2: Smart Robot</title>

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css">

    <style>

        .well-robot {

            min-height: 340px;

        }

        .input-robot {

            width: 100%;

            min-height: 100px;

        }

        .output-robot {

            border: 1px solid #000000;

            min-height: 150px;

            margin-top: 10px;

        }

    </style>

</head>

<body>

    <div class="container">

        <div class="alert alert-info">

            Hello! I'm a smart robot. I can do many interesting things. Type something below and click a button to watch me work!

        </div>

        <div class="row">

            <div class="col-sm-4">

                <img src="./robot.gif">

            </div>

            <div class="col-sm-8 well well-robot">

                <textarea id="robotInput" placeholder="Input something here!" class="input-robot"></textarea>

                <div class="btn-group btn-group-justified">

                    <a class="btn btn-default" id="vowels">Count Vowels</a>

                    <a class="btn btn-default" id="words">Count Words</a>

                    <a class="btn btn-default" id="punctuation">Count Punctuation</a>

                </div>

                <div id="robotResult" class="output-robot">

                </div>

            </div>

        </div>

    </div>

    <script src="./robot.js"></script>

</body>

</html>

Explanation / Answer

If you have any doubts, please give me comment...

robot.js

document.getElementById("vowels").onclick = function() {

var text = document.getElementById("robotInput").value;

vowels = { "a": 0, "e": 0, "i": 0, "o": 0, "u": 0 };

text = text.toLowerCase();

for (i = 0; i < text.length; i++) {

if (text[i] == 'a' || text[i] == 'e' || text[i] == 'i' || text[i] == 'o' || text[i] == 'u')

vowels[text[i]]++;

}

var str = "";

for (k in vowels) {

str += "<li>" + k + " - " + vowels[k] + "</li>";

}

document.getElementById("robotResult").innerHTML = "<ul>" + str + "</ul>";

}

document.getElementById("words").onclick = function() {

var text = document.getElementById("robotInput").value;

words = {};

text = text.toLowerCase().split(" ");

for (i = 0; i < text.length; i++) {

if (words[text[i]] == undefined)

words[text[i]] = 0;

else

words[text[i]]++;

}

var str = "";

for (k in words) {

str += "<li>" + k + " - " + words[k] + "</li>";

}

document.getElementById("robotResult").innerHTML = "<ul>" + str + "</ul>";

}

document.getElementById("punctuation").onclick = function() {

var text = document.getElementById("robotInput").value;

punc = {};

text = text.toLowerCase();

for (i = 0; i < text.length; i++) {

if (text[i] == '.' || text[i] == ',' || text[i] == ';' || text[i] == ':' || text[i] == '!') {

if (punc[text[i]] == undefined)

punc[text[i]] = 0;

else

punc[text[i]]++;

}

}

var str = "";

for (k in punc) {

str += "<li>" + k + " - " + punc[k] + "</li>";

}

document.getElementById("robotResult").innerHTML = "<ul>" + str + "</ul>";

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote