Skip to content

Instantly share code, notes, and snippets.

@Charpell
Last active June 28, 2020 09:16
Show Gist options
  • Save Charpell/8dd2ef484c551ab919bd0bbc92a25161 to your computer and use it in GitHub Desktop.
Save Charpell/8dd2ef484c551ab919bd0bbc92a25161 to your computer and use it in GitHub Desktop.
Exercise 1
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'))
@Charpell
Copy link
Author

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

@adedoyin89
Copy link

Thank you Sir.

@Charpell
Copy link
Author

Welcome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment