My program must change the case of my word on UpperCase or LowerCase.
Example:
word: "cAPS"
solution: "Caps"
All good, but.
My program works well with one word.
The program checks case of my word by two first symbols(Uppercase or Lower case) But when deal going to sentence I have a problem.
I do not understand, how method I must use. Maybe need to use an array or cycle to doing this?
My problem:
word: "wHY DO wE NEED cAPS lOCK?"
Code of my program:
let newWord = 'cAPS'
word = newWord
if (word.length > 1) {
var lengthWord = word.length
if (word.substring(1) == word.toUpperCase().substring(1)) {
newWord = word.toUpperCase(0, 1).substring(0, 1) +
word.toLowerCase().substring(1)
console.log(newWord)
} else if (word.substring(0) == word.toUpperCase().substring(0)) {
newWord = word.toLowerCase().substring(0)
console.log(newWord)
} else if (word.substring(0, 1) == word.toUpperCase().substring(0, 1)) {
newWord = word
console.log(newWord)
}
}