Today is my first day learning JavaScript, and I have been researching closures online. However, I am struggling to understand how to use closures in the code I have written:
function writeit()
{
var tbox = document.getElementById('a_tbox').value;
var letters = tbox.split("");
for(var i=0;i<letters.length;i++)
{
if(letters[i]==="a")
{
document.a_form.b_tbox.value = i+1 + ". character is a";
}
else if(letters[i]==="b")
{
document.a_form.b_tbox.value = i+1 + ". character is b";
}
else
{
document.a_form.b_tbox.value = i+1 + ". character is not a nor b";
}
}
}
I am trying to extract a string from a text box, convert it into an array, and modify each value using a for loop. Ideally, if a user inputs "abc" into the text box, I would like the output to be "1. value is a 2. value is b 3. value is not a nor b". However, the current output only shows "3. value is not a nor b". How can I correct this issue?