1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| let str = 'hELLo'; let ans = '';
// console.log(String.fromCharCode(65, 90,97, 122));
for(let i = 0; i < str.length; i++) { let temp = str.charCodeAt(i) // console.log(temp); if(temp >= 65 && temp <= 90) { ans += String.fromCharCode(temp + 32); } else { if (temp >= 97 && temp <= 122) { ans += String.fromCharCode(temp - 32); } else { ands += str[i]; } } }
console.log('ans', ans);
|