So I've been doing the Odin Project and I'm at functions right now and there's a task "Write a function called capitalize that takes a string and returns that string with only the first letter capitalized. Make sure that it can take strings that are lowercase, UPPERCASE or BoTh."
<script>
function capitalize(myName, myNameUpper, myNameRan) {
const toUpper = "Bartek";
myName = "bartek";
myNameUpper = "BARTEK";
myNameRan = "BaRtEk";
myName, myNameUpper, myNameRan = toUpper;
console.log(myName, myNameUpper, myNameRan)
}
capitalize();
</script>
Is my function any good? Thanks in advance for help.
CodePudding user response:
<script>
function capitalize(lowercase,uppercase,both ) {
const capitalizeLower = lowercase.charAt(0).toUpperCase() lowercase.slice(1).toLowerCase();
const capitalizeUpper = uppercase.charAt(0).toUpperCase() uppercase.slice(1).toLowerCase();
const capitalizeBoth = both.charAt(0).toUpperCase() both.slice(1).toLowerCase();
console.log(capitalizeLower, capitalizeUpper , capitalizeBoth)
return `${capitalizeLower} ${capitalizeUpper} ${capitalizeBoth}`
}
capitalize("hello","HELLO","hEllO");
</script>