Assignment 9

by grettynebraska

HTML

<div id="inputDiv" class="left">
Input:<br/>
<textarea id="inputArea"></textarea>
</div>
<div id="buttonDiv" class="left">
<input type="button" id="runButton" value="Run Program">
</div>
<div id="outputDiv" class="left">
Output:<br/>
<textarea id="outputArea"></textarea>
</div>

CSS

.left{
  float: left;
}
.right{
  float: right;
}
.clear{
  clear: both;
}
.hidden{
  display: none;
}
.hint{
  font-size: 75%;
  font-style: italic;
}
#inputDiv, #outputDiv{
  width: 40%;
  padding: 10px;
}
#buttonDiv{
  width: 10%;
  text-align: center;
  padding-top: 30px;
}
#runButton{
  padding: 5px;
}
#inputArea, #outputArea{
  width: 100%;
  height: 200px;
}

/* The switch - the box around the slider */
.switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 15px;
}

/* Hide default HTML checkbox */
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

/* The slider */
.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  -webkit-transition: .4s;
  transition: .4s;
}

.slider:before {
  position: absolute;
  content: "";
  height: 11px;
  width: 11px;
  left: 2px;
  bottom: 2px;
  background-color: white;
  -webkit-transition: .4s;
  transition: .4s;
}

input:checked + .slider {
  background-color: #099;
}

input:focus + .slider {
  box-shadow: 0 0 1px #099;
}

input:checked + .slider:before {
  -webkit-transform: translateX(26px);
  -ms-transform: translateX(26px);
  transform: translateX(26px);
}

/* Rounded sliders */
.slider.round {
  border-radius: 34px;
}

.slider.round:before {
  border-radius: 50%;
}

JavaScript

//wow this practice is awesome and hard and intense, it's  great!

//Main function
function main() {
  var input = readLine();

  var wordCount = print(countWords(input));

  var ranLetter = randomLetter();
  var randomLetterCount = print(countWordsWith(input, ranLetter));
  letterFrequency(input);
}

function randomLetter() {
  var alpha = "a b c d e f g h i j k l m n o p q r s t u v w x y z";
  var alphaArr = alpha.split(" ");
  var randomN = Math.floor(Math.random() * 25);
  var randomLetter = "";
  for (var i = 0; i < alphaArr.length; i++) {
    if (i == randomN) {
      randomLetter = alphaArr[i];
      return randomLetter;
    }
  }
}

function countWords(text) {
  var arr = text.split(" ");
  var arrLength = arr.length;
  return "Your input text has " + arrLength + " words.";
}

function countWordsWith(text, letter) {
  var letterCount = 0;
  var textLetterSplit = text.split("");
  //print(textLetterSplit);
  for (var i = 0; i < textLetterSplit.length; i++) {
    if (textLetterSplit[i].includes(letter)) {
      letterCount++;
    }
  }
  return "There are " + letterCount + " with the randomly selected letter " + letter + ".";
}

function letterCount(textArr,alphaLoopLetter) {
	var count = 0;
  for(var i=0; i<textArr.length; i++) {
  	if(textArr[i] == alphaLoopLetter) {
    	count++;
    }
  }
  //loop through the length of the text
  	//if each letter matches the input letter, increase the count.
  
  return count;
}

function letterFrequency(text) {
	var output = [];
  var alphabet = "abcdefghijklmnopqrstuvwxyz";
  var alphaArr = alphabet.split("");
  var textLetterSplit = text.toLowerCase().split("");
  
  for(var i = 0; i < alphaArr.length; i++) {
    print(alphaArr[i] + ": " + letterCount(textLetterSplit, alphaArr[i]));
  }
  //loop through all 26 letters in the alphabet
 		//use letter count(text, whatever letter youre on)
    //store that number into the output array
}













function multipleVision(string, n) {
  var output = "";
  for (var i...