File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ function capitalise(str) {
88 return str ;
99}
1010
11- // he error message says 'str' has already been declared so we can use another name for our
11+ // Te error message says 'str' has already been declared so we can use another name for our
1212//output to solve that error we change the output variable name
1313// function capitalise(str) {
1414 // let str = `${str[0].toUpperCase()}${str.slice(1)}`;
Original file line number Diff line number Diff line change 1414// Then when we call this function with the weight and height
1515// It should return their Body Mass Index to 1 decimal place
1616
17- function calculateBMI ( weight , height ) {
18- let bmi = weight / height * height ;
19- return bmi ;
17+ function calculateBMI ( weight , height ) {
18+ return ( weight / ( height * height ) ) . toFixed ( 1 ) ;
19+
2020 // return the BMI of someone based off their weight and height
2121}
22- console . log ( `Your BMI is ${ bmi } ` )
22+ console . log ( `Your BMI is ${ calculateBMI ( 56 , 1.5 ) } ` )
23+ //console.log(`Your BMI is ${calculateBMI(weight,height)}`)
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 caseToUpperS ( string ) {
18+ return string . toUpperCase ( ) . replaceAll ( " " , "_" ) ;
19+
20+ }
21+ console . log ( `Your new word is ${ caseToUpperS ( "i love cyf so much" ) } ` )
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+ function toPounds ( penceString ) {
8+
9+ let penceStringWithoutTrailingP = penceString . substring (
10+ 0 ,
11+ penceString . length - 1
12+ ) ;
13+
14+ let paddedPenceNumberString = penceStringWithoutTrailingP . padStart ( 3 , "0" ) ;
15+ let pounds = paddedPenceNumberString . substring (
16+ 0 ,
17+ paddedPenceNumberString . length - 2
18+ ) ;
19+
20+ let pence = paddedPenceNumberString
21+ . substring ( paddedPenceNumberString . length - 2 )
22+ . padEnd ( 2 , "0" ) ;
23+
24+ return { pounds, pence} ;
25+ }
26+ const { pounds, pence } = toPounds ( "10390p" ) ;
27+
28+ console . log ( `£${ pounds } .${ pence } ` ) ;
29+
30+
31+
32+ // This program takes a string representing a price in pence
33+ // The program then builds up a string representing the price in pounds
34+
35+ // You need to do a step-by-step breakdown of each line in this program
36+ // Try and describe the purpose / rationale behind each step
37+
38+ // To begin, we can start with
39+ // 1. const penceString = "399p": initialises a string variable with the value "399p"
You can’t perform that action at this time.
0 commit comments