Skip to content

Commit 52eee8a

Browse files
authored
Create LowercaseToUppercase.js
1 parent d18bcda commit 52eee8a

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Strings/LowercaseToUppercase.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// upper converts lowercase sting to upper case
2+
// input is 1 string i.e. str
3+
const upper = (str) => {
4+
// check that inputs are string
5+
if (typeof str !== "string") {
6+
return "Not string(s)";
7+
}
8+
9+
var convertedString = "";
10+
11+
for (let i = 0; i < str.length; i++) {
12+
if (str.charCodeAt(i) >= 97 && str.charCodeAt(i) <= 122) {
13+
convertedString =
14+
convertedString + String.fromCharCode(65 + str.charCodeAt(i) - 97);
15+
continue;
16+
}
17+
convertedString = convertedString + str.charAt(i);
18+
}
19+
20+
return convertedString;
21+
};
22+
23+
console.log(upper("abcd")); // should print ABCD
24+
console.log(upper("abcd1")); // should print ABCD1
25+
console.log(upper("*abcd")); // *ABCD
26+
console.log(upper("aBs")); // should print ABS

0 commit comments

Comments
 (0)