i am trying to show all the locations the letter ‘e’ that shows up in a string for my homework.
How do I start?
Here is the question and my attempts. some have been commented out because they did not match what i was looking for in the answer.
show the location of each occurence of the character “e” in the string “beg”
// *** on one line separated by commas in the span block with id=“ans6”
//
//var begE = beg.match(/e/g) //document.getElementById(“ans6”).innerHTML=(beg.indexOf(‘e’))
// THIS METHOD COUNTS TOTAL OCCURANCE OF E COULD BE USEFUL IN NUMBER 5
var begE = 0
var positionE = 0
//for (i=0;i<beg.length;i++){
//positionE = (beg.indexOf(‘e’)
while begE= (beg.indexOf(‘e’) != -1)
positionE=begE.toString()
document.getElementById(“ans6”).innerHTML=(begE)
var text = "eeennennennnenne";
var charFound=[];
var searching = true;
while (searching) {
for ( var i=0, len =text.length; i < len ; i++) {
if ( text[i] === 'e') {
charFound.push(i);
}
}
searching = false;
charFound = charFound.join();
}
console.log( charFound);