
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Replace Uppercase and Lowercase in a String using JavaScript
We are required to write a JavaScript function that takes in a string and constructs a new string with all the uppercase characters converted to lowercase and all the lowercase characters converted to uppercase.
Let’s write the code for this function −
Example
Following is the code −
const str = 'The Case OF tHis StrinG Will Be FLiPped'; const isUpperCase = char => char.charCodeAt(0) >= 65 && char.charCodeAt(0) char.charCodeAt(0) >= 97 && char.charCodeAt(0) { let newStr = ''; const margin = 32; for(let i = 0; iOutput
The output in the console: −
tHE cASE of ThIS sTRINg wILL bE flIpPED
Advertisements