Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Strings/LowercaseToUppercase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// upper converts lowercase sting to upper case
// input is 1 string i.e. str
const upper = (str) => {
// check that inputs are string
if (typeof str !== "string") {
return "Not string(s)";
}

var convertedString = "";

for (let i = 0; i < str.length; i++) {
if (str.charCodeAt(i) >= 97 && str.charCodeAt(i) <= 122) {
convertedString =
convertedString + String.fromCharCode(65 + str.charCodeAt(i) - 97);
continue;
}
convertedString = convertedString + str.charAt(i);
}

return convertedString;
};

console.log(upper("abcd")); // should print ABCD
console.log(upper("abcd1")); // should print ABCD1
console.log(upper("*abcd")); // *ABCD
console.log(upper("aBs")); // should print ABS