[Solved] for loop assingment javascript


You can sequentially loop through the string and append the inverted character to another string.

You can check whether the character is lowercase or not by converting it to lowercase (with String.toLowerCase) and checking whether the result is equal to the original.

let swappedName = "elZerO";

let res = "";
for (let i = 0; i < swappedName.length; i++) {
  const current = swappedName.charAt(i);
  res += current == current.toLowerCase() ? current.toUpperCase() : current.toLowerCase();
}

console.log(res)

1

solved for loop assingment javascript