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...
2- // =============> write your prediction here
32
4- // call the function capitalise with a string input
3+ // =============> write your prediction here
4+ //A) You are likely to encounter a syntax error because the variable `str` is being declared twice within the same scope
55// interpret the error message and figure out why an error is occurring
66
77function capitalise ( str ) {
8- let str = `${ str [ 0 ] . toUpperCase ( ) } ${ str . slice ( 1 ) } ` ;
9- return str ;
8+ let capitalisedStr = `${ str [ 0 ] . toUpperCase ( ) } ${ str . slice ( 1 ) } ` ;
9+ return capitalisedStr ;
1010}
1111
12- // =============> write your explanation here
13- // =============> write your new code here
12+ console . log ( capitalise ( "hello" ) ) ;
Original file line number Diff line number Diff line change 22
33// Why will an error occur when this program runs?
44// =============> write your prediction here
5+ // An error will occur because the variable `decimalNumber` is being declared twice within the same scope
6+
57
68// Try playing computer with the example to work out what is going on
79
810function convertToPercentage ( decimalNumber ) {
9- const decimalNumber = 0.5 ;
1011 const percentage = `${ decimalNumber * 100 } %` ;
11-
1212 return percentage ;
1313}
1414
15- console . log ( decimalNumber ) ;
15+ console . log ( convertToPercentage ( 0.5 ) ) ;
1616
1717// =============> write your explanation here
1818
Original file line number Diff line number Diff line change 44// this function should square any number but instead we're going to get an error
55
66// =============> write your prediction of the error here
7+ // an error will occur because the value `3` has been put in the parentheses of the function.
78
8- function square ( 3 ) {
9+
10+ function square ( num ) {
911 return num * num ;
1012}
13+ console . log ( square ( 3 ) ) ;
1114
1215// =============> write the error message here
16+ // SyntaxError: Unexpected number
1317
1418// =============> explain this error message here
19+ // An error occurs because the function parameter `3` is a literal value instead of a variable name.
1520
1621// Finally, correct the code to fix the problem
1722
23+
1824// =============> write your new code here
1925
2026
You can’t perform that action at this time.
0 commit comments