File tree Expand file tree Collapse file tree 4 files changed +43
-5
lines changed Expand file tree Collapse file tree 4 files changed +43
-5
lines changed Original file line number Diff line number Diff line change 1515// It should return their Body Mass Index to 1 decimal place
1616
1717function calculateBMI ( weight , height ) {
18- // return the BMI of someone based off their weight and height
19- }
18+ // return the BMI of someone based off their weight and height
19+ const bmi = weight / ( height * height ) ;
20+ return parseFloat ( bmi . toFixed ( 1 ) ) ;
21+ }
22+ console . log ( calculateBMI ( 70 , 1.73 ) ) ; // This line is inserted only to test the function. It returns 23.4
23+ console . log ( calculateBMI ( 80 , 1.8 ) ) ; // This line is inserted only to test the function. It returns 24.7
24+ console . log ( calculateBMI ( 90 , 1.75 ) ) ; // This line is inserted only to test the function. It returns 29.4
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+ function toUpperSnakeCase ( str ) {
18+ // return the string in UPPER_SNAKE_CASE
19+ return str . toUpperCase ( ) . replace ( / / g, "_" ) ;
20+ }
21+ console . log ( toUpperSnakeCase ( "hello there" ) ) ; // This line is inserted only to test the function. It returns "HELLO_THERE"
22+ console . log ( toUpperSnakeCase ( "lord of the rings" ) ) ; // This line is inserted only to test the function. It returns "LORD_OF_THE_RINGS"
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+ function toPounds ( penceString ) {
9+ // Convert a string representing an amount in pence (e.g., "123p") to pounds and pence format (e.g., "£1.23")
10+
11+ const penceStringWithoutTrailingP = penceString . substring (
12+ 0 ,
13+ penceString . length - 1
14+ ) ;
15+
16+ const paddedPenceNumberString = penceStringWithoutTrailingP . padStart ( 3 , "0" ) ;
17+ const pounds = paddedPenceNumberString . substring (
18+ 0 ,
19+ paddedPenceNumberString . length - 2
20+ ) ;
21+
22+ const pence = paddedPenceNumberString
23+ . substring ( paddedPenceNumberString . length - 2 )
24+ . padEnd ( 2 , "0" ) ;
25+
26+ return `£${ pounds } .${ pence } ` ;
27+ }
28+ console . log ( toPounds ( "5555p" ) ) ; // This line is inserted only to test the function. It returns "£55.55"
29+ console . log ( toPounds ( "399p" ) ) ; // This line is inserted only to test the function. It returns "£0.05"
30+ console . log ( toPounds ( "50p" ) ) ; // This line is inserted only to test the function. It returns "£0.50"
31+ console . log ( toPounds ( "500p" ) ) ; // This line is inserted only to test the function. It returns "£5.00"
Original file line number Diff line number Diff line change @@ -10,20 +10,22 @@ function formatTimeDisplay(seconds) {
1010
1111 return `${ pad ( totalHours ) } :${ pad ( remainingMinutes ) } :${ pad ( remainingSeconds ) } ` ;
1212}
13+ console . log ( formatTimeDisplay ( 61 ) ) ; // This line is inserted only to test the function. It returns "00:01:01"
1314
15+ // Here is a function that takes a number of seconds and returns a string formatted as "HH:MM:SS"
1416// You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit
1517// to help you answer these questions
1618
1719// Questions
1820
1921// a) When formatTimeDisplay is called how many times will pad be called?
2022// =============> write your answer here
21-
23+ //3 times
2224// Call formatTimeDisplay with an input of 61, now answer the following:
23-
25+ // 00:01:01
2426// b) What is the value assigned to num when pad is called for the first time?
2527// =============> write your answer here
26-
28+ //61
2729// c) What is the return value of pad is called for the first time?
2830// =============> write your answer here
2931
You can’t perform that action at this time.
0 commit comments