Hi everyone 👋
I started learning JavaScript today and practiced string methods like slice(), length, toUpperCase(), toLowerCase(), and concatenation.
I wrote this small snippet to take user input and convert the first character to uppercase while keeping the rest lowercase.
Here’s the code:
var name = prompt("What is your name?");
var sliceresult = name.slice(0, 1);
var ni = sliceresult.toUpperCase();
var low = name.slice(1, name.length);
var nn = low.toLowerCase();
alert("Hello " + ni + nn + "!");Question :
-
Is this logic correct for basic name capitalization?
-
Are there cleaner or more idiomatic ways to do this in JavaScript?
-
Anything I should avoid or improve as a beginner?
Thanks!