feat(curriculum): Add interactive examples to How Can You Change the Casing for a String (#63227)

This commit is contained in:
Clarence Bakosi 2025-10-29 19:10:15 +01:00 committed by GitHub
parent fdbd33a9a7
commit 4464c123a5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -5,7 +5,7 @@ challengeType: 19
dashedName: how-can-you-change-the-casing-for-a-string
---
# --description--
# --interactive--
When working with strings in JavaScript, there are many situations where you might need to adjust the case of the text, such as transforming all letters to uppercase for a heading or converting text to lowercase for uniformity.
@ -15,12 +15,16 @@ The `toUpperCase()` method converts all the characters to uppercase letters and
Let's see an example:
:::interactive_editor
```js
let greeting = "Hello, World!";
let uppercaseGreeting = greeting.toUpperCase();
console.log(uppercaseGreeting); // Output: "HELLO, WORLD!"
console.log(uppercaseGreeting); // "HELLO, WORLD!"
```
:::
In this code, the `toUpperCase()` method transforms the entire string into uppercase letters.
The original string remains unchanged because `toUpperCase()` returns a new string, rather than modifying the original one.
@ -29,12 +33,16 @@ On the flip side, the `toLowerCase()` method converts all characters in a string
Let's look at an example:
:::interactive_editor
```js
let shout = "I AM LEARNING JAVASCRIPT!";
let lowercaseShout = shout.toLowerCase();
console.log(lowercaseShout); // Output: "i am learning javascript!"
console.log(lowercaseShout); // "i am learning javascript!"
```
:::
The `toLowerCase()` method converts all characters to lowercase, making the string less aggressive, while leaving the original string unchanged.
In summary, the `toUpperCase()` and `toLowerCase()` methods in JavaScript are powerful tools for transforming strings into all uppercase or lowercase letters.