File tree Expand file tree Collapse file tree 1 file changed +5
-22
lines changed
Sprint-2/3-mandatory-implement Expand file tree Collapse file tree 1 file changed +5
-22
lines changed Original file line number Diff line number Diff line change 55
66// You should call this function a number of times to check it works for different inputs
77
8- const toPounds = ( kg ) => + ( kg * 2.20462 ) . toFixed ( 2 ) ;
9-
10- const penceToPounds = ( p ) => `£${ ( p / 100 ) . toFixed ( 2 ) } ` ;
11- const toUpperSnakeCase = ( s ) => s . toUpperCase ( ) . trim ( ) . split ( " " ) . join ( "_" ) ;
12- const multiply = ( a , b ) => a * b ;
8+ const penceToPounds = ( p ) => {
9+ const value = parseInt ( p . replace ( "p" , "" ) ) ;
10+ return `£${ ( value / 100 ) . toFixed ( 2 ) } ` ;
11+ } ;
1312
1413// Tests
15- console . log ( toPounds ( 10 ) ) ; // 22.05
16-
17- console . log ( penceToPounds ( 150 ) ) ; // "£1.50"
18-
19- console . log ( toUpperSnakeCase ( "hello there" ) ) ;
20- // "HELLO_THERE"
21- console . log ( multiply ( 10 , 32 ) ) ; // 320
22-
23- const convertToUpperSnakeCase = ( str ) =>
24- str . toUpperCase ( ) . trim ( ) . split ( " " ) . join ( "_" ) ;
14+ console . log ( penceToPounds ( "399p" ) ) ; // "£3.99"
2515
26- console . log ( convertToUpperSnakeCase ( "hello there" ) ) ; // "HELLO_THERE"
2716
28- // Four functions are implemented because each one performs a specific task.
29- // This makes the code easier to read, reuse, and maintain.
30- //
31- // The penceToPounds function was updated to handle a pence string like "399p".
32- // It removes the "p", converts the value to a number, and divides by 100
33- // so the function correctly returns "£3.99".s
You can’t perform that action at this time.
0 commit comments