1if (character == character.toLowerCase())
2{
3 // The character is lowercase
4}
5else
6{
7 // The character is uppercase
8}
9//The problem with this answer is,
10//that some characters like numbers or punctuation
11//also return true when checked for lowercase/uppercase.
12
13// this is the solution for it:
14function isLowerCase(str)
15{
16 return str == str.toLowerCase() && str != str.toUpperCase();
17}
1let name = "Collins Rollins"
2let rename = name.toLowerCase();
3console.log(rename);
4//OUTPUT: "collins rollins"
1// A minified version of the other one:
2const hasLowerCase= s => s.toUpperCase() != s;
3
4console.log("HeLLO: ", hasLowerCase("HeLLO"));
5console.log("HELLO: ", hasLowerCase("HELLO"));
1function hasLowerCase(str) {
2 return str.toUpperCase() != str;
3}
4
5console.log("HeLLO: ", hasLowerCase("HeLLO"));
6console.log("HELLO: ", hasLowerCase("HELLO"));