File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
Sprint-2/3-mandatory-implement Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments