File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change 44// You will need to declare a function called toPounds with an appropriately named parameter.
55
66// You should call this function a number of times to check it works for different inputs
7+
8+
9+
10+
11+
12+ const penceString = "399p" ;
13+
14+ const penceStringWithoutTrailingP = penceString . substring (
15+ 0 ,
16+ penceString . length - 1
17+ ) ;
18+
19+ const paddedPenceNumberString = penceStringWithoutTrailingP . padStart ( 3 , "0" ) ;
20+ const pounds = paddedPenceNumberString . substring (
21+ 0 ,
22+ paddedPenceNumberString . length - 2
23+ ) ;
24+
25+ const pence = paddedPenceNumberString
26+ . substring ( paddedPenceNumberString . length - 2 )
27+ . padEnd ( 2 , "0" ) ;
28+
29+ console . log ( `£${ pounds } .${ pence } ` ) ;
30+
31+ // This program takes a string representing a price in pence
32+ // The program then builds up a string representing the price in pounds
33+
34+ // You need to do a step-by-step breakdown of each line in this program
35+ // Try and describe the purpose / rationale behind each step
36+
37+ // To begin, we can start with
38+ // 1. const penceString = "399p": initialises a string variable with the value "399p"
39+
You can’t perform that action at this time.
0 commit comments