So I'm trying to build this project where I ask the user to enter their name, then I display said name in full and put the initials in a button instead of "player one". I don't know why but slice(-1), charAt(str.length -1) are not working.
<div> <label for="name">Enter your name</label> <input type="text" name="" id="yn"> <button class="submit">Submit</button> </div> <p class="welcome"></p>
var yourname = document.querySelector("#yn"); var welcome = document.querySelector(".welcome"); var div = document.querySelector("div"); var submit = document.querySelector(".submit"); submit.addEventListener("click", function(){ div.classList.add("hide"); welcome.textContent = "Welcome " + yourName.value })
Thanks
Top comments (4)
There's a typo
wrong:
correct:
Okay thanks. I've corrected it
And here is what you want:
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