Caps

Easy

Prompt

Write a function that takes a single string argument and returns the string in all uppercase letters.

Example

console.log(caps('upper')); // UPPER

Playground

Hint 1

Use JavaScript's toUpperCase() method on the string to convert it to uppercase.

Hint 2

String methods in JavaScript don't modify the original string - they return a new string.

Solution

Explanation

String manipulation is foundational to programming, and converting text to uppercase is one of the most common operations you'll perform. Let's break down how our solution works:

The caps function takes a single parameter input, which should be a string. It then applies JavaScript's built-in String.prototype.toUpperCase() method to convert the string to uppercase and returns the result.

return input.toUpperCase();

Here's what happens when the function executes:

  1. JavaScript calls the toUpperCase() method on the input string
  2. This method creates a new string where all alphabetic characters are converted to their uppercase equivalents
  3. Non-alphabetic characters (numbers, symbols, spaces) remain unchanged
  4. The new string is returned from the function
00:00