Skip to content

Commit 183aa5b

Browse files
committed
Implement toUpperSnakeCase function to convert strings to UPPER_SNAKE_CASE
1 parent ab8b7e0 commit 183aa5b

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Sprint-2/3-mandatory-implement/2-cases.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,30 @@
1414
// You will need to come up with an appropriate name for the function
1515
// Use the MDN string documentation to help you find a solution
1616
// This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase
17+
18+
function toUpperSnakeCase(str) {
19+
// return the string in UPPER_SNAKE_CASE
20+
}
21+
22+
// Predict and explain first...
23+
// =============> write your prediction here
24+
// I predict that the code will output 'undefined' because the function toUpperSnakeCase
25+
// does not currently return anything.
26+
27+
// =============> write your explanation here
28+
// The function needs to replace spaces in the string with underscores ("_")
29+
// and then convert all the letters to uppercase.
30+
// We can do this using string methods:
31+
// - replaceAll(" ", "_") (or replace(/ /g, "_") for older versions of JS)
32+
// - toUpperCase() to convert to uppercase.
33+
34+
// Finally, correct the code to fix the problem
35+
// =============> write your new code here
36+
37+
function toUpperSnakeCase(str) {
38+
return str.replaceAll(" ", "_").toUpperCase();
39+
}
40+
41+
// Example:
42+
console.log(toUpperSnakeCase("hello there")); // Output: HELLO_THERE
43+
console.log(toUpperSnakeCase("lord of the rings")); // Output: LORD_OF_THE_RINGS

0 commit comments

Comments
 (0)