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

Please help me for making JavaScript I need to implement 3 simple tasks based on

ID: 3585309 • Letter: P

Question

Please help me for making JavaScript

I need to implement 3 simple tasks based on what the user inputs.

The html is

The html is ok, but I need make JavaScript.

The first is Count Vowels. The user can type a sentence into the input area then click the Count Vowels buttons. The robot will then output an unordered list in the black box area below the buttons with each vowel that appeared in the sentence and how many occurrences it found. The robot will ignore all punctuation and will also not consider ‘y’ a vowel. A screenshot example is below.

The second is Count Anagrams. The user can type a sentence into the input area and click the Count Anagrams button. The robot will then ouput a sentence telling the user how many words were found that can be made into an anagram with another word in that sentence. The robot will consider two words to be an anagram if the letters can be re-arranged so that they match. For example, “iceman” and “cinema” are anagrams. The robot will ignore all punctuation. A screenshot example is below.

The third, and final, is Word Distance. The user can type two words into the input area and click the Word Distance button. The robot will then output a sentence with how many transformations it would take to turn the first word into the second. If the robot needs to add, remove, or change a letter, that counts as 1 transformation per operation performed. The robot can shift letters around for free. A screenshot example is below.

Rejections are following

You use any third party JavaScript libraries

You use var instead of let

You don’t use the EventListener API

You don’t create DOM elements via JavaScript or the DOM API (ie don’t set innerHTML or innerText with Strings)

If any errors or console logs appear in the browser’s web developer console

42141 euioa

Explanation / Answer

Hi,

I have done with the three javascript functions and i am unable to load the images that you have provided. Please check below code and is there doubts raise the comment here.

------------------

robot.js   create with below code.

function countVowels(){
document.getElementById("robotResult").innerHTML = "";
var inputString = document.getElementById("roboInput").value;
//alert(inputString);
var vowels = "";
    for (var i=0; i < inputString.length;i++) {
        if((inputString.charAt(i) == 'a') ||
            (inputString.charAt(i) == 'e') ||
            (inputString.charAt(i) == 'i') ||
            (inputString.charAt(i) == 'o') ||
            (inputString.charAt(i) == 'u')) {
     vowels += inputString.charAt(i);
        }
    }
var div = document.getElementById('robotResult');
div.innerHTML = 'Vowels:'+vowels;
//vowels count
if (vowels.indexOf('a') > -1){
  if(vowels.count("a")!=0){
   div.innerHTML+="<br/> a Count: "+vowels.count("a");
  }
}
if (vowels.indexOf('e') > -1){
  if(vowels.count("e")!=0){
   div.innerHTML+="<br/> e Count: "+vowels.count("e");
  }
}
if (vowels.indexOf('i') > -1){
  if(vowels.count("i")!=0){
   div.innerHTML+="<br/> i Count: "+vowels.count("i");
  }
}
if (vowels.indexOf('o') > -1){
  if(vowels.count("o")!=0){
   div.innerHTML+="<br/> o Count: "+vowels.count("o");
  }
}
if (vowels.indexOf('u') > -1){
  if(vowels.count("u")!=0){
   div.innerHTML+="<br/> u Count: "+vowels.count("u");
  }
}


}
String.prototype.count=function(s1) {  
   return (this.length - this.replace(new RegExp(s1,"g"), '').length) / s1.length;
}
// count anagrams function

function countAngrams(){
var divid = document.getElementById("robotResult");
divid.innerHTML = "";
var inputString = document.getElementById("roboInput").value;
var vals = inputString.split(" ");
if(vals.length>1){
  
  for(var i=0;i<vals.length;i++){
   //alert(sortAlphabets( vals[i] ));
   var str1 = sortAlphabets( vals[i] );
   for(var j=i+1;j<vals.length;j++){
    var str2 = sortAlphabets( vals[j] );
    
    if(str1.length==str2.length){
     
     if(str1==str2){
      divid.innerHTML+=vals[i]+" and "+vals[j]+" Anagrams<br/>";
     }
     
    }
    
   }
   if(divid.innerHTML == ""){
    divid.innerHTML+="No Anagrams found<br/>";
   }
   
  }
  
}else{
  alert("Please enter atleast two words to check anagrams");
}
}
var sortAlphabets = function(text) {
text=text.toLowerCase();
    return text.split('').sort().join('');
};

function wordDistance(){
var divid = document.getElementById("robotResult");
divid.innerHTML = "";
var inputString = document.getElementById("roboInput").value;
var vals = inputString.split(" ");
var noofTransoforms=0;
if(vals.length==2){
  
  if(vals[0].length==vals[1].length){
  
   var str1 = vals[0].split('');
   var str2 = vals[1].split('');
   for(var m=0;m<str1.length;m++){
    
    if(str1[m]!=str2[m]){
     noofTransoforms++;
    }
    
   }
   
  
  }else if(vals[0].length>vals[1].length){
   var str1 = vals[0].split('');
   var str2 = vals[1].split('');
   for(var m=0;m<str1.length;m++){
    if(m==str2.length-1){
     noofTransoforms+= str1.length-str2.length;
     break;
    }
    if(str1[m]!=str2[m]){
     noofTransoforms++;
    }
    
    
   }
  }else{
   var str1 = vals[0].split('');
   var str2 = vals[1].split('');
   for(var m=0;m<str2.length;m++){
    if(str1[m]!=str2[m]){
     noofTransoforms++;
    }
    if(m==str1.length-1){
     noofTransoforms+= str2.length-str1.length;
     break;
    }
    
    
   }
  }
  alert("total count:"+noofTransoforms);
  
}else{
  alert("Please enter Only two words to check word distance");
}

}

-------------------HTML CODE------------------

<!DOCTYPE html>
<!-- Do not edit this file, only make my 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="roboInput" 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="anagrams">Count Anagrams</a>
                                        <a class="btn btn-default" id="distance">Word Distance</a>
                                </div>
                                <div id="robotResult" class="output-robot">
                                </div>
                        </div>
                </div>
        </div>
        <script src="robot.js"></script>
</body>
</html>

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