Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

194
Vistas
Finding a name's index inside a Variable

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 />`;
about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

you can using "indexing", like this:

name[0] //first letter
name[name.length-1] //last letter, remember that js sequences are 0 indexed
about 4 years ago · Santiago Gelvez Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda