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

Let me be real with you - you probably won't get asked this exact question in an interview. But here's the thing - it's still super helpful to understand this concept because it shows up as part of solving many other interview questions you will face! And even if it does come up, it'll likely be in a different format, like a multiple-choice question rather than asking you to code it from scratch. Consider this as building your problem-solving toolkit that will help you tackle tougher challenges down the road!

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