Q:

Write a JavaScript program to change the capitalization of all letters in a given string

0

Write a JavaScript program to change the capitalization of all letters in a given string.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

function change_case(txt) {
    var str1 = "";
    for (var i = 0; i < txt.length; i++) {
        if (/[A-Z]/.test(txt[i])) str1 += txt[i].toLowerCase();
        else str1 += txt[i].toUpperCase();
    }
    return str1;
}

console.log(change_case("w3resource"));
console.log(change_case("Germany"));

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now