Using this JavaScript code snippet, you can convert lowercase letters to uppercase without relying on built-in functions. This is a helpful concept to understand for interviews and coding challenges.
//change lower case to upper case
function Change_Upper_Case() {
var inputArray = [], outputArray = [], index = 0; // defining variables
inputArray = document.getElementById('EnterString').value; // retrieving user input
while(index < inputArray.length) {
var currentChar = inputArray[index];
var charCode = currentChar.charCodeAt(0); //getting ASCII value of the character
var transformedChar = currentChar;
if(charCode >= 97 && charCode < 123) {
var convertedCharCode = charCode - 32;
transformedChar = String.fromCharCode(convertedCharCode);
}
outputArray[index] = transformedChar;
index++;
}
document.getElementById('ShowString').innerHTML = outputArray.join('');
}
// HTML input fields
<input type="text" id="EnterString"/>
<input type="button" value="Upper Case" onclick="Change_Upper_Case()"/>
<span id="ShowString"></span><br/>