How to make a variable uppercase

let favoriteAnimal = 'lion'

console.log('My favorite animal: ' + toUpperCase(favoriteAnimal))

Can I change the first letter of the variable using “toUpperCase”?

Hey there! There’s something not right there, you would get an error. This is the correct way of using the function .toUpperCase(), read more here.

let favoriteAnimal = 'lion';

console.log('My favorite animal: ' + favoriteAnimal.toUpperCase());

//output is: "My favorite animal: LION"

If you want just the “L” of lion to be uppercase you can explicitly define it so. E.g.:

console.log('My favorite animal: ' + favoriteAnimal[0].toUpperCase() + favoriteAnimal.slice(1));

//output is: "My favorite animal: Lion"

Read more about the .slice() method.

Hope this helps :slight_smile:

1 Like

Thank you so much. This help and clarifies my doubt.

1 Like