Skip to content

Commit 7b05d22

Browse files
committed
Enhance comments for clarity and consistency across key error examples
1 parent 04cdbd3 commit 7b05d22

6 files changed

Lines changed: 50 additions & 27 deletions

File tree

Sprint-2/1-key-errors/0.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Predict and explain first...
22

33
// =============> 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
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

77
function capitalise(str) {

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
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
5+
// (A)An error will occur because the variable `decimalNumber` is being declared twice within the same scope
66

77

88
// Try playing computer with the example to work out what is going on
@@ -13,8 +13,3 @@ function convertToPercentage(decimalNumber) {
1313
}
1414

1515
console.log(convertToPercentage(0.5));
16-
17-
// =============> write your explanation here
18-
19-
// Finally, correct the code to fix the problem
20-
// =============> write your new code here

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

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,16 @@
66
// =============> write your prediction of the error here
77
// an error will occur because the value `3` has been put in the parentheses of the function.
88

9-
10-
function square(num) {
11-
return num * num;
12-
}
13-
console.log(square(3));
14-
159
// =============> write the error message here
16-
// SyntaxError: Unexpected number
10+
// (A) SyntaxError: Unexpected number
1711

1812
// =============> explain this error message here
19-
// An error occurs because the function parameter `3` is a literal value instead of a variable name.
13+
// (A)An error occurs because the function parameter `3` is a literal value instead of a variable name.
2014

21-
// Finally, correct the code to fix the problem
2215

23-
24-
// =============> write your new code here
16+
function square(num) {
17+
return num * num;
18+
}
19+
console.log(square(3));
2520

2621

Sprint-2/2-mandatory-debug/0.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
// Predict and explain first...
22

33
// =============> write your prediction here
4+
//(A) An error will occur because the function `multiply` does not return a value.
45

5-
function multiply(a, b) {
6+
/*function multiply(a, b) {
67
console.log(a * b);
78
}
89
9-
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
10+
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);*/
1011

1112
// =============> write your explanation here
13+
// (A) It returns `undefined`. This results in the output being "The result of multiplying 10 and 32 is undefined".
14+
//
15+
16+
function multiply(a, b) {
17+
return a * b;
18+
}
1219

13-
// Finally, correct the code to fix the problem
14-
// =============> write your new code here
20+
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);

Sprint-2/2-mandatory-debug/1.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3+
//(A) An error will occur because the function `sum` does not return a value. The `return` statement is followed by a semicolon, the function will return `undefined`
34

4-
function sum(a, b) {
5+
6+
/*function sum(a, b) {
57
return;
68
a + b;
79
}
810
9-
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
11+
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);*/
1012

1113
// =============> write your explanation here
1214
// Finally, correct the code to fix the problem
1315
// =============> write your new code here
16+
17+
function sum(a, b) {
18+
return a + b;
19+
}
20+
21+
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);

Sprint-2/2-mandatory-debug/2.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,42 @@
22

33
// Predict the output of the following code:
44
// =============> Write your prediction here
5+
// (A) The output will be "The last digit of... is 3" for all these due the the variable `num` being set to 103 and the function `getLastDigit`
56

6-
const num = 103;
7+
8+
/*const num = 103;
79
810
function getLastDigit() {
911
return num.toString().slice(-1);
1012
}
1113
1214
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
1315
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
14-
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
16+
console.log(`The last digit of 806 is ${getLastDigit(806)}`);*/
1517

1618
// Now run the code and compare the output to your prediction
1719
// =============> write the output here
20+
/*The last digit of 42 is 3
21+
The last digit of 105 is 3
22+
The last digit of 806 is 3*/
23+
24+
1825
// Explain why the output is the way it is
19-
// =============> write your explanation here
26+
//(A) As predicted the output resunts last digit of the variable `num`, which is set to 103. Therefore, regardless of the input values (42, 105, 806), the function always returns '3'.
27+
2028
// Finally, correct the code to fix the problem
2129
// =============> write your new code here
2230

31+
function getLastDigit(num) {
32+
return num.toString().slice(-1);
33+
}
34+
35+
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
36+
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
37+
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
38+
39+
40+
41+
2342
// This program should tell the user the last digit of each number.
2443
// Explain why getLastDigit is not working properly - correct the problem

0 commit comments

Comments
 (0)