File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11// Predict and explain first...
22
33// Why will an error occur when this program runs?
4- // =============> Instead of calling the function, a variable is called
4+ // =============> Line 9 the variable "decimalNumber" is declared as a parameter passed to the function
5+ // but again on line 10 inside the function, the variable is declared
56
67// Try playing computer with the example to work out what is going on
78
9+ const decimalNumber = 0.5 ;
810function convertToPercentage ( decimalNumber ) {
9- const decimalNumber = 0.5 ;
1011 const percentage = `${ decimalNumber * 100 } %` ;
1112
1213 return percentage ;
1314}
1415
15- console . log ( decimalNumber ) ;
16-
17- // =============> Also inside the function, decimalNumber is called again
16+ console . log ( convertToPercentage ( decimalNumber ) ) ;
1817
1918// Finally, correct the code to fix the problem
2019// =============> decimalNumber = 0.5;
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// =============> The variable num is not declared
76
8- function square ( 3 ) {
9- return num * num ;
7+ function square ( num ) {
8+ return num * num ;
109}
10+ console . log ( square ( 3 ) ) ;
1111
1212// =============>SyntaxError: Unexpected number
1313
@@ -16,5 +16,3 @@ function square(3) {
1616// Finally, correct the code to fix the problem
1717
1818// =============> function square(num) {
19-
20-
Original file line number Diff line number Diff line change 1717function calculateBMI ( weight , height ) {
1818 // return the BMI of someone based off their weight and height
1919 const bmi = weight / height ** 2 ;
20- return bmi . toFixed ( 1 ) ;
20+ return parseFloat ( bmi . toFixed ( 1 ) ) ;
2121}
2222console . log ( calculateBMI ( 70 , 1.73 ) ) ;
Original file line number Diff line number Diff line change 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
1717function makeUpperSnakeCase ( str ) {
18- return str . toUpperCase ( ) . split ( " " ) . join ( "_" ) ;
18+ return str . toUpperCase ( ) . replaceAll ( " " , "_" ) ;
1919}
Original file line number Diff line number Diff line change 44
55function formatAs12HourClock ( time ) {
66 const hours = Number ( time . slice ( 0 , 2 ) ) ;
7- const minutes = time . slice ( 3 ) ;
7+ const minutes = time . slice ( - 2 ) ;
88 if ( hours === 0 ) return `12:${ minutes } am` ;
99 else if ( hours === 12 ) return `12:${ minutes } pm` ;
1010 else if ( hours > 12 ) {
You can’t perform that action at this time.
0 commit comments