File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -25,4 +25,4 @@ function capitalise(str) {
2525 str = `${ str [ 0 ] . toUpperCase ( ) } ${ str . slice ( 1 ) } ` ;
2626 return str ;
2727}
28- console . log ( capitalise ( "hellllo" ) ) ;
28+ console . log ( capitalise ( "hellllo" ) ) ;
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
6+ // Answer: I predict that we will get a Reference Error: num is not defined. Or perhaps an error about the 3, as
7+ // it is a number and therefore not a valid parameter name. I believe perhaps parameter names are like variable
8+ // names and can't start with a number.
79
10+ /*
811function square(3) {
912 return num * num;
1013}
14+ */
1115
1216// =============> write the error message here
17+ // Answer: SyntaxError: Unexpected number
1318
1419// =============> explain this error message here
20+ // Answer: Yes we got an error message about the number 3. We wouldn't get a message about num not being defined
21+ // since the function isn't called in the code, so the inside of the function can't produce an error.
22+ // I will first try to update the 3 to n3, to see if it is a valid parameter name and see if the error goes away,
23+ // just as an experiment.
24+
25+ // Answer: The error did go away. However it didn't solve our problem as we still want to receive 3 squared when
26+ // calling the function. I will change n3 to the proper parameter name, num. So it can be referenced inside the
27+ // function body. Then I will make a function call and pass in 3 there, as an argument to the parameter num.
28+ // Then I will log the result to see if it worked.
1529
1630// Finally, correct the code to fix the problem
1731
1832// =============> write your new code here
1933
34+ function square ( num ) {
35+ return num * num ;
36+ }
2037
38+ console . log ( square ( 3 ) ) ;
You can’t perform that action at this time.
0 commit comments