JavaScript: Inverse letter case

Last update: 14 Sep 12:25
1
Student
100%
Completion rate

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