Javascript: Inverse letter case

JavaScript fundamentals
Last update: 15 Jul 23:20
0
Students

invertCase.js

Implement and export as default a function that changes the case of each letter in the string to the opposite.

Examples:

invertCase('Hello, World!'); // hELLO, wORLD!
invertCase('I loVe JS');     // i LOvE js

Tips

  • To find out the length of a string, use the length property:
'welcome'.length; // 7
  • To convert a string (or a single character) to uppercase, use the toUpperCase() method:
'foo'.toUpperCase(); // 'FOO';
'f'.toUpperCase();   // 'F';
  • To convert a string (or a single character) to lowercase, use the toLowerCase() method
'BAR'.toLowerCase(); // 'bar';
'b'.toLowerCase();   // 'b';

For full access to the challenge you need a professional subscription.

A professional subscription will give you full access to all Hexlet courses, projects and lifetime access to the theory of lessons learned. You can cancel your subscription at any time.

Get access
130
courses
1000
exercises
2000+
hours of theory
3200
tests