File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66// You should call this function a number of times to check it works for different inputs
77
88function toPounds ( penceString ) {
9- const penceStringWithoutTrailingP = penceString . substring (
10- 0 ,
11- penceString . length - 1
12- ) ;
9+ const penceStringWithoutTrailingP = penceString . substring (
10+ 0 ,
11+ penceString . length - 1
12+ ) ;
1313
14- const paddedPenceNumberString = penceStringWithoutTrailingP . padStart ( 3 , "0" ) ;
15- const pounds = paddedPenceNumberString . substring (
16- 0 ,
17- paddedPenceNumberString . length - 2
18- ) ;
14+ const paddedPenceNumberString = penceStringWithoutTrailingP . padStart ( 3 , "0" ) ;
15+ const pounds = paddedPenceNumberString . substring (
16+ 0 ,
17+ paddedPenceNumberString . length - 2
18+ ) ;
1919
20- const pence = paddedPenceNumberString
21- . substring ( paddedPenceNumberString . length - 2 )
22- . padEnd ( 2 , "0" ) ;
20+ const pence = paddedPenceNumberString
21+ . substring ( paddedPenceNumberString . length - 2 )
22+ . padEnd ( 2 , "0" ) ;
2323
24- console . log ( `£${ pounds } .${ pence } ` ) ;
24+ return `£${ pounds } .${ pence } ` ;
25+ }
26+
27+ console . log ( toPounds ( "1p" ) ) ;
28+ console . log ( toPounds ( "90p" ) ) ;
29+ console . log ( toPounds ( "303p" ) ) ;
30+ console . log ( toPounds ( "23456p" ) ) ;
Original file line number Diff line number Diff line change @@ -21,15 +21,15 @@ function formatTimeDisplay(seconds) {
2121// Questions
2222
2323// a) When formatTimeDisplay is called how many times will pad be called?
24- // =============> write your answer here
24+ // =============> 3
2525
2626// Call formatTimeDisplay with an input of 61, now answer the following:
2727
2828// b) What is the value assigned to num when pad is called for the first time?
29- // =============> write your answer here
29+ // =============> 1
3030
3131// c) What is the return value of pad is called for the first time?
32- // =============> write your answer here
32+ // =============> "01"
3333
3434// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer
3535// =============> write your answer here
Original file line number Diff line number Diff line change @@ -23,3 +23,17 @@ console.assert(
2323 currentOutput2 === targetOutput2 ,
2424 `current output: ${ currentOutput2 } , target output: ${ targetOutput2 } `
2525) ;
26+
27+ const currentOutput3 = formatAs12HourClock ( "13:15" ) ;
28+ const targetOutput3 = "1:15 pm" ;
29+ console . assert (
30+ currentOutput3 === targetOutput3 ,
31+ `current output: ${ currentOutput3 } , target output: ${ targetOutput3 } `
32+ ) ;
33+
34+ const currentOutput4 = formatAs12HourClock ( "12:00" ) ;
35+ const targetOutput4 = "12:00 am" ;
36+ console . assert (
37+ currentOutput4 === targetOutput4 ,
38+ `current output: ${ currentOutput4 } , target output: ${ targetOutput4 } `
39+ ) ;
You can’t perform that action at this time.
0 commit comments