Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

193
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!