File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1111*/
1212
1313// The error happens because str is declared twice, once as a parameter & again with let
14- // If I give the new variable a different name, I hope it should work :)
15-
14+ // If I give the new variable a different name, I hope it should work :)
1615
1716function capitalise ( str ) {
1817 let newString = `${ str [ 0 ] . toUpperCase ( ) } ${ str . slice ( 1 ) } ` ;
1918 return newString ;
2019}
2120
22- console . log ( capitalise ( "frumentius" ) ) ;
21+ console . log ( capitalise ( "frumentius" ) ) ;
Original file line number Diff line number Diff line change @@ -29,4 +29,4 @@ function convertToPercentage(decimalNumber) {
2929 return percentage ;
3030}
3131
32- console . log ( convertToPercentage ( "26" ) ) ;
32+ console . log ( convertToPercentage ( "26" ) ) ;
Original file line number Diff line number Diff line change 1-
21// Predict and explain first BEFORE you run any code...
32
43// this function should square any number but instead we're going to get an error
54
65// =============> write your prediction of the error here
76// I think using 3 will cause an error as parameter
8- // A parameter must be a valid variable name, not a number
7+ // A parameter must be a valid variable name, not a number
98
10- /* function square(3){
9+ /* function square(3){
1110 return num * num;
1211
1312}
1413 */
15-
16- // =============> write the error message here
14+
15+ // =============> write the error message here
1716// SyntaxError: Unexpected number
1817
1918// =============> explain this error message here
2019// The parser sees the number 3 where it expects a valid parameter name,
2120// so it cannot understand the structure of the function
2221// It means we cannot use a number as a parameter name
2322
24-
2523// Finally, correct the code to fix the problem
2624
2725// =============> write your new code here
2826
29- function square ( num ) {
30- return num * num ;
31-
27+ function square ( num ) {
28+ return num * num ;
3229}
33- console . log ( square ( 7 ) ) ;
30+ console . log ( square ( 7 ) ) ;
Original file line number Diff line number Diff line change 11// Predict and explain first...
22
33// =============> write your prediction here
4- // I believe the function will calculate 10 x 32
4+ // I believe the function will calculate 10 x 32
55
66function multiply ( a , b ) {
77 console . log ( a * b ) ;
8-
98}
109
1110console . log ( `The result of multiplying 10 and 32 is ${ multiply ( 10 , 32 ) } ` ) ;
1211
1312// =============> write your explanation here
1413
15- // After calling multiply(10, 32), the result is undefined because there is no return statement
14+ // After calling multiply(10, 32), the result is undefined because there is no return statement
1615// It can still print 320 because console.log() prints the result inside the function
1716
1817// Finally, correct the code to fix the problem
@@ -22,4 +21,4 @@ function multiply(a, b) {
2221 console . log ( a * b ) ;
2322 return a * b ;
2423}
25- console . log ( `The result of multiplying 10 and 32 is ${ multiply ( 10 , 32 ) } ` ) ;
24+ console . log ( `The result of multiplying 10 and 32 is ${ multiply ( 10 , 32 ) } ` ) ;
Original file line number Diff line number Diff line change 11// Predict and explain first...
22// =============> write your prediction here
3- // I guess the function will return error or undefined because the return;
3+ // I guess the function will return error or undefined because the return;
44
55/*function sum(a, b) {
66 return;
Original file line number Diff line number Diff line change 22
33// Predict the output of the following code:
44// =============> Write your prediction here
5- // The output will be the same because we don't give the function a parameter
5+ // The output will be the same because we don't give the function a parameter
66
77/*const num = 103;
88
@@ -22,7 +22,6 @@ console.log(`The last digit of 806 is ${getLastDigit(806)}`); */
2222// =============> write your explanation here
2323// Because of the global variable and also because the function has no parameter
2424
25-
2625// Finally, correct the code to fix the problem
2726// =============> write your new code here
2827
@@ -36,8 +35,7 @@ console.log(`The last digit of 42 is ${getLastDigit(42)}`);
3635console . log ( `The last digit of 105 is ${ getLastDigit ( 105 ) } ` ) ;
3736console . log ( `The last digit of 806 is ${ getLastDigit ( 806 ) } ` ) ;
3837
39-
4038// This program should tell the user the last digit of each number.
4139// Explain why getLastDigit is not working properly - correct the problem
4240
43- // Because the function was using the global variable, it ignored the arguments passed to it outside of the function box
41+ // Because the function was using the global variable, it ignored the arguments passed to it outside of the function box
Original file line number Diff line number Diff line change 1515// It should return a string of their Body Mass Index to 1 decimal place
1616
1717function calculateBMI ( weight , height ) {
18- let BMI = weight / ( height * height )
19-
20- return BMI . toFixed ( 1 ) ;
18+ let BMI = weight / ( height * height ) ;
2119
22-
20+ return BMI . toFixed ( 1 ) ;
2321}
2422console . log ( calculateBMI ( 62 , 1.67 ) ) ;
2523
26- // return the BMI of someone based off their weight and height
24+ // return the BMI of someone based off their weight and height
Original file line number Diff line number Diff line change 1616// This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase
1717
1818function toUpper ( input ) {
19- return input . replaceAll ( " " , "_" ) . toUpperCase ( ) ;
20-
19+ return input . replaceAll ( " " , "_" ) . toUpperCase ( ) ;
2120}
2221
2322console . log ( toUpper ( "alpha and omega" ) ) ;
Original file line number Diff line number Diff line change 55
66// You should call this function a number of times to check it works for different inputs
77
8-
9-
10-
11-
128function toPounds ( amount ) {
13- const amountWithoutTrailingP = amount . substring (
14- 0 ,
15- amount . length - 1
16- ) ;
9+ const amountWithoutTrailingP = amount . substring ( 0 , amount . length - 1 ) ;
1710
18- const paddedPenceNumberString = amountWithoutTrailingP . padStart ( 3 , "0" ) ;
19- const pounds = paddedPenceNumberString . substring (
20- 0 ,
21- paddedPenceNumberString . length - 2
22- ) ;
11+ const paddedPenceNumberString = amountWithoutTrailingP . padStart ( 3 , "0" ) ;
12+ const pounds = paddedPenceNumberString . substring (
13+ 0 ,
14+ paddedPenceNumberString . length - 2 ,
15+ ) ;
2316
24- const pence = paddedPenceNumberString
25- . substring ( paddedPenceNumberString . length - 2 )
26- . padEnd ( 2 , "0" ) ;
17+ const pence = paddedPenceNumberString
18+ . substring ( paddedPenceNumberString . length - 2 )
19+ . padEnd ( 2 , "0" ) ;
2720
28- return ( `£${ pounds } .${ pence } ` )
21+ return `£${ pounds } .${ pence } ` ;
2922}
3023
31-
3224console . log ( toPounds ( "1250p" ) ) ;
33-
34-
Original file line number Diff line number Diff line change @@ -14,12 +14,12 @@ const currentOutput = formatAs12HourClock("08:00");
1414const targetOutput = "08:00 am" ;
1515console . assert (
1616 currentOutput === targetOutput ,
17- `current output: ${ currentOutput } , target output: ${ targetOutput } `
17+ `current output: ${ currentOutput } , target output: ${ targetOutput } ` ,
1818) ;
1919
2020const currentOutput2 = formatAs12HourClock ( "23:00" ) ;
2121const targetOutput2 = "11:00 pm" ;
2222console . assert (
2323 currentOutput2 === targetOutput2 ,
24- `current output: ${ currentOutput2 } , target output: ${ targetOutput2 } `
24+ `current output: ${ currentOutput2 } , target output: ${ targetOutput2 } ` ,
2525) ;
You can’t perform that action at this time.
0 commit comments