File tree Expand file tree Collapse file tree 3 files changed +34
-2
lines changed
Sprint-2/3-mandatory-implement Expand file tree Collapse file tree 3 files changed +34
-2
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+ let bmi = weight / ( height * height ) ;
19+ return Math . round ( bmi * 10 ) / 10
20+ }
21+
22+ // console.log(calculateBMI(68, 1.7));
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+
18+ function toUpperSnake ( str ) {
19+ return str . split ( " " ) . map ( item => item . toUpperCase ( ) ) . join ( "_" ) ;
20+ }
21+
22+ console . log ( toUpperSnake ( "lord of the rings" ) ) ;
23+ // 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+ // Method 1
9+ function toPounds ( penceString ) {
10+ let penceStringWithoutP = penceString . substring ( 0 , penceString . length - 1 ) ;
11+ let paddedPenceNumberString = penceStringWithoutP . padStart ( 3 , "0" ) ;
12+ let pound = paddedPenceNumberString . substring ( 0 , paddedPenceNumberString . length - 2 ) ;
13+ let pence = paddedPenceNumberString . substring ( paddedPenceNumberString . length - 2 ) ;
14+
15+ return `£${ pound } .${ pence } ` ;
16+
17+ }
18+ console . log ( toPounds ( "447p" ) ) ; // £4.47
19+
20+
21+
22+ // Method 2
23+ function toPounds ( penceString ) {
24+ let value = Number ( penceString . slice ( 0 , - 1 ) ) / 100 ;
25+ return `£${ value . toFixed ( 2 ) } `
26+ }
27+
28+ console . log ( toPounds ( "447p" ) ) ; // £4.47
You can’t perform that action at this time.
0 commit comments