Skip to content

Commit cf6d301

Browse files
committed
Predicted and answered 2.js in errors (and formatted 0.js)
1 parent 73c7f27 commit cf6d301

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

‎Sprint-3/1-key-errors/0.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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"));

‎Sprint-3/1-key-errors/2.js‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,38 @@
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+
/*
811
function 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));

0 commit comments

Comments
 (0)