I have some exercises that are a little ambiguous: I have to find the first index of any name that is defined inside a prompt(), but the problem is that using indexOf() I must define a letter to start the search.
Is there an efficient way to define what would be the first and last letter of variable names that have not been explained to me in the course?
const name = prompt('please, type your name here);
document.body.innerHTML += `What's the first letter of your name? ${name.indexOf(0)}<br />`;
document.body.innerHTML += `What's the last letter of your name? ${name.lastIndexOf(-1)}<br />`;
Edit: I ended up finding a .CHM document that contained JS instructions, and in it I discovered the Slice() method, I ended up finding a solution for the first letter, but how could I always choose the last letter of any name within a variable?
Answer for the first letter:
document.body.innerHTML += `What's the first letter of your name ${name.slice(0, 1)}<br />`;