Lonely E's Task

Task where subject must "cross off" all the "lonely e's" in the text.

by David Zuckerman

HTML

<head>
<style>
h2 {
  position: absolute;
  left: 350px;
  top: 200px;
}
</style>
</head>
<body>
<canvas id="myCanvas" width="800" height="200"></canvas>

<h2><button id="checkAnswers">Check My Answers</button></h2>
</body>

JavaScript

var canvas = document.getElementById("myCanvas");

var ctx = canvas.getContext("2d");

var verticalSpacing = 25;

var charLineLimit = 60;


var arrayTest =[0, 1, 2, 3, 4, 5, 6, 7]



var crossOut = "e";

ctx.fillStyle = "#000000";
ctx.font = "20px Courier"; //the width of the letter will be 3/5 of this. 

var ascent = [15, 10] //gives ascent of an upper- and lower-case figure, respectively 
var letterWidth = 12; 

var text = "He said he was not there yesterday; however, many people saw him there. This book is sure to liquefy your brain. Going from child, to childish, to childlike is only a matter of time. She found his complete dullness interesting. Nobody questions who built the pyramids in Mexico. Her daily goal was to improve on yesterday."

//identifies all "lonely e's" in a string of text. Returns an array with these indices
function findLonelyEs(textStr){
	var indices = [];
  textStr = textStr.toLowerCase(); //when finding e's, converting everythign to lower case
  //checking the first two indices separately
  if(textStr[0] === crossOut && !isVowel(textStr[1]) && !isVowel(textStr[2])){
  	indices.push(0);
  }
  
  if(textStr[1] === crossOut && !isVowel(textStr[0]) && !isVowel(textStr[2]) && !isVowel(textStr[3])){
  	indices.push(1);
  }
  
  //Looping through the string, recording any "lonely e's"
  for(var i = 2; i < textStr.length - 2; i++){
  
  //testing if character is a "lonely e"
  	if(textStr[i] === "e" && !isVowel(textStr[i-2]) && !isVowel(textStr[i-1]) && !isVowel(textStr[i+1]) && !isVowel(textStr[i+2])){ 
    	indices.push(i);
    }
  }
  
  //checking the last two indices separately
  var lastIdx = textStr.length - 1
  if(textStr[lastIdx - 1] === crossOut && !isVowel(textStr[lastIdx - 3]) && !isVowel(textStr[lastIdx - 2]) && !isVowel(textStr[lastIdx])){
  	indices.push(lastIdx - 1);
  }
  
  if(textStr[lastIdx] === crossOut && !isVowel(textStr[lastIdx - 2]) && !isVowel(textStr[lastIdx - 1])){
  	indices.push(lastIdx);
  }
  
  return...