DEV Community

Discussion on: How do I get the first/last char of a string from a user input (input.value)

Collapse
 
morrisjohn profile image
Morris John

Okay thanks. I've corrected it

Collapse
 
donnii profile image
Daniel Dark

And here is what you want:

submit.addEventListener('click', () => {

    const {value} = yourName

    const firstChar = value.slice(0, 1)
    const lastChar = value.slice(-1)

    div.classList.add('hide')
    welcome.textContent = firstChar + lastChar
})
Thread Thread
 
morrisjohn profile image
Morris John • Edited

Wow, that worked.

I don't even understand the code (*LOL I haven't learnt the 'const / {} => yet *) but yeah it worked.

Thank you very much