Last active
June 28, 2020 09:16
-
-
Save Charpell/8dd2ef484c551ab919bd0bbc92a25161 to your computer and use it in GitHub Desktop.
Exercise 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function firstLetter(name) { | |
if (typeof(name) !== "string" || name.length < 3) return "Incorrect Input" | |
const removedLetter = name.slice(0, -1) | |
const result = name[0].toUpperCase() + removedLetter.slice(1) | |
return result | |
} | |
console.log('firstLetter', firstLetter('Obito')) |
Thank you Sir.
Welcome
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
On Line 2, I am checking the user argument, if the argument is not a string or the argument is less than 3 characters, its a bad argument so I immediately return an error mesaage and stop the function from executing further.
On Line 3, I removed letter and assign it to a new variable
On line 4, I took the first letter and changed it to uppercase then added it to a sliced function excluding the first