-1

I have a code here but I don't understand how to convert it. The prompt should be asking your name but I need to make the first letter uppercase. The characters should be on lowercase.

var myName = "Rafael";

var messge = "Hello";

var yourName = prompt("What is your name? ");

console.log("My name is " + myName + ", " + messge + " " + yourName + "." );
0stone0
  • 34,288
  • 4
  • 39
  • 64

1 Answers1

1

var myName = "Rafael";

var messge = "Hello";

var yourName = prompt("What is your name? ");

yourName = yourName.charAt(0).toUpperCase() + yourName.slice(1).toLowerCase();

console.log("My name is " + myName + ", " + messge + " " + yourName + "." );

Try this.

Bani
  • 542
  • 4
  • 20
  • Not that one, there is a prompt that would ask for your name. The name you will put is what I want to make the first letter uppercase while the rests are lowercase. – Jake Pacholski Feb 07 '23 at 11:51
  • The First letter works but I still need the rest of the other characters in lowercase. Sorry about this, I'm so new to programming – Jake Pacholski Feb 07 '23 at 12:05
  • yourName = yourName.charAt(0).toUpperCase() + yourName.slice(1).toLowerCase(); – Jake Pacholski Feb 07 '23 at 12:10
  • @JakePacholski you dont need .toLowerCase(); at the end, if you press at Run code snippet at my answer and then type in lets say `jake` at the end you will get `Hello Jake` – Bani Feb 07 '23 at 12:11
  • Ok thanks btw, really appreciate it. I was actually required to maintain the second and other characters in lowercase. For example, If I type "JAKE.", the result is all capitalized, it won't be "Jake." The code worked somehow. – Jake Pacholski Feb 07 '23 at 12:21
  • @JakePacholski yeah in that case `.toLowerCase()` is needed at the end, also all good its a pleasure to help others. Ill update my answer and add that there. – Bani Feb 07 '23 at 12:23