File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed
Sprint-2/3-mandatory-implement Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change 14
14
// You will need to come up with an appropriate name for the function
15
15
// Use the MDN string documentation to help you find a solution
16
16
// This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase
17
+
18
+ function toUpperSnakeCase ( str ) {
19
+ // Replace spaces with underscores and convert to uppercase
20
+ return str . replace ( / / g, "_" ) . toUpperCase ( ) ;
21
+ }
22
+
23
+
24
+ console . log ( toUpperSnakeCase ( "hello there" ) ) ; // "HELLO_THERE"
25
+ console . log ( toUpperSnakeCase ( "lord of the rings" ) ) ; // "LORD_OF_THE_RINGS"
Original file line number Diff line number Diff line change 4
4
// You will need to declare a function called toPounds with an appropriately named parameter.
5
5
6
6
// You should call this function a number of times to check it works for different inputs
7
+
8
+ function toPounds ( penceString ) {
9
+ // Remove trailing 'p' and pad with zeros to ensure at least 3 digits
10
+ const pence = penceString . substring ( 0 , penceString . length - 1 ) . padStart ( 3 , "0" ) ;
11
+ // Get pounds and pence parts
12
+ const pounds = pence . substring ( 0 , pence . length - 2 ) ;
13
+ const pencePart = pence . substring ( pence . length - 2 ) . padEnd ( 2 , "0" ) ;
14
+ // Return formatted string
15
+ return `£${ pounds } .${ pencePart } ` ;
16
+ }
17
+
18
+
19
+ console . log ( toPounds ( "399p" ) ) ; // £3.99
20
+ console . log ( toPounds ( "9p" ) ) ; // £0.09
21
+ console . log ( toPounds ( "99p" ) ) ; // £0.99
22
+ console . log ( toPounds ( "100p" ) ) ; // £1.00
23
+ console . log ( toPounds ( "1234p" ) ) ; // £12.34
You can’t perform that action at this time.
0 commit comments