Assignment 8

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

//Main function
function main() {

  var line = "";
  var allLines = [];
  while ((line = readLine()) != "") {
    allLines.push(line);
  }

  print(allLines.sort());

  var sortedLines = (insertionSort_GStore(sortAlpha(allLines)));
  print("\n final list sorted first alphabetically and then by word length: ");
  for (var i = 0; i < sortedLines.length; i++) {
    print(sortedLines[i]);
  }
}

function sortAlpha(list) {
  var listSorted = list.sort();
  print("Alphabetically sorted list: ");
  for (var g = 0; g < listSorted.length; g++) {
    print(listSorted[g]);
  }
  print("\n");
  return (listSorted);

}

function insertionSort_GStore(list) {
  var output = list.slice(0);
  print("alphabetically sorted list, now passed into the Insertion Sort function and sliced: " + output);
  for (var i = 1; i < output.length; i++) {
    for (var k = i; k > 0 && wordLength(output[k]) < wordLength(output[k - 1]); k--) {
      var temp = output[k];
      output[k] = output[k - 1];
      output[k - 1] = temp;
    }
  }
  return output;
}

function wordLength(word) {
  return (word.length);
}






function func(a, b) {
  if (b == 0) {
    return a;
  }
  return (func(b, a % b));
}

function multipleVision(string, n) {
  var output = "";
  for (var i = 0; i < n; i++) {
    output += string;
  }
  return output;
}

function halver(n) {
  return n / 2;
}

function doubleVision(string) {
  return string + string;
}



function calculator() {
  var zoeRecord = 1.21;
  var coolLamp = 2.33;
  var shorts = 0.95;

  var input;
  var total = 0;

  while ((input = readLine()) != "") {
    var arr = input.split(" ");
    if (arr[0] == "add") {
      if (arr[1] == "record") {
        total += zoeRecord;
        print("record - $" + zoeRecord);
      } else if (arr[1] == "lamp") {
        total += coolLamp;
        print("lamp - $" + coolLamp);
      } else {
        total += shorts;
        print("shorts - $" + shorts);
      }
    } else {
      if (arr[1] == "record") {
        total -=...