- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Program to make vowels in string uppercase and change letters to next letter in alphabet (i.e. z->a) in JavaScript
We are required to write a JavaScript function that takes in a string as the only input.
The function should construct a new string based on the input string in which all the vowels should be uppercased and change each alphabet to the corresponding next alphabet.
For example − If the input string is −
const str = 'newString';
Therefore, the output for the above input should look like this −
const output = 'oExSusIoh';
Example
The code for this will be −
const str = 'newString'; const capitiliseAndMove = (str = '') => { let s = ''; s = str.replace(/[a−z]/g, function(c) { return 'aeiou'.indexOf(c) > −1 ? c.toUpperCase() : String.fromCharCode(Math.max(c.charCodeAt(0) % 122 + 1, 97)); }); return s; }; console.log(capitiliseAndMove(str));
Output
And the output in the console will be −
oExSusIoh
Advertisements