Introduction
In this lab, we will explore how to check if a given string is in uppercase using JavaScript. We will create a function that converts the string to uppercase using the String.prototype.toUpperCase() method, and then compare it to the original string. By the end of this lab, you will have a better understanding of string manipulation in JavaScript and how to check for uppercase strings.
Function to Check if a String is Uppercase
To check if a string is in uppercase, follow these steps:
- Open the Terminal/SSH.
- Type
node. - Use the function
isUpperCase()to convert the given string to uppercase, usingString.prototype.toUpperCase(), and compare it to the original string. - The function will return
trueif the string is in uppercase andfalseif it is not.
Here is an example code:
const isUpperCase = (str) => str === str.toUpperCase();
console.log(isUpperCase("ABC")); // true
console.log(isUpperCase("A3@$")); // true
console.log(isUpperCase("aB4")); // false
Summary
Congratulations! You have completed the String Is Uppercase lab. You can practice more labs in LabEx to improve your skills.