Toggle String

PHOTO EMBED

Sun May 01 2022 22:58:34 GMT+0000 (Coordinated Universal Time)

Saved by @GreenMark #javascript

//Toggle String
// Sample code to perform I/O:

process.stdin.resume();
process.stdin.setEncoding("utf-8");
var stdin_input = "";

process.stdin.on("data", function (input) {
    stdin_input += input;                               // Reading input from STDIN
});

process.stdin.on("end", function () {
   main(stdin_input);
});

function main(input) {
    var data= input.toString().split("\n");

    process.stdout.write(toggle(data[0]));       // Writing output to STDOUT
}

// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail



// Write your code here
// Sample code to perform I/O:
//Enter your code here


function toggle(s) {
    var ss="";
    for (var i= 0; i<s.length; i++) {
        
        if (s[i] >= 'a' && s[i] <= 'z') {
           ss= ss+String.fromCharCode(s.charCodeAt(i) - 32);
        } else if (s[i] >= 'A' && s[i] <= 'Z') {
            ss= ss+String.fromCharCode(s.charCodeAt(i) + 32);
         
        }
            
    }    
    return ss;    
}
     
content_copyCOPY

Problem You have been given a String S consisting of uppercase and lowercase English alphabets. You need to change the case of each alphabet in this String. That is, all the uppercase letters should be converted to lowercase and all the lowercase letters should be converted to uppercase. You need to then print the resultant String to output. Input Format The first and only line of input contains the String S Output Format Print the resultant String on a single line. Constraints where S denotes the length of string S. Sample Input abcdE Sample Output ABCDe

https://www.hackerearth.com/practice/basic-programming/input-output/basics-of-input-output/practice-problems/algorithm/modify-the-string/