Skip to content

Commit 21acb1b

Browse files
committed
Completed other exercises for section 1
1 parent 7e9bb59 commit 21acb1b

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,30 @@
22

33
// Why will an error occur when this program runs?
44
// =============> write your prediction here
5+
// My prediction of the error is that nothing will be displayed because console.log isn't calling a function
6+
// it is just calling a variable that is not defined in this scope.
57

68
// Try playing computer with the example to work out what is going on
79

8-
function convertToPercentage(decimalNumber) {
9-
const decimalNumber = 0.5;
10-
const percentage = `${decimalNumber * 100}%`;
10+
// function convertToPercentage(decimalNumber) {
11+
// const decimalNumber = 0.5;
12+
// const percentage = `${decimalNumber * 100}%`;
1113

12-
return percentage;
13-
}
14+
// return percentage;
15+
// }
1416

15-
console.log(decimalNumber);
17+
// console.log(decimalNumber);
1618

1719
// =============> write your explanation here
20+
// The error occurs because the variable 'decimalNumber' is the parameter of the function
21+
// but it is being re-declared inside the function which causes a conflict.
1822

1923
// Finally, correct the code to fix the problem
2024
// =============> write your new code here
25+
function convertToPercentage(decimalNumber) {
26+
const percentage = `${decimalNumber * 100}%`;
27+
28+
return percentage;
29+
}
30+
31+
console.log(convertToPercentage(0.5));

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
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+
// Prediction of the error is that the function parameter is not valid.
7+
// It should be a variable name, not a number.
78

8-
function square(3) {
9-
return num * num;
10-
}
9+
// function square(3) {
10+
// return num * num;
11+
// }
1112

1213
// =============> write the error message here
14+
// SyntaxError: Unexpected number
1315

1416
// =============> explain this error message here
17+
// The error message indicates that there is an unexpected number in the function parameter list.
1518

1619
// Finally, correct the code to fix the problem
1720

1821
// =============> write your new code here
22+
function square(num) {
23+
return num * num;
24+
}
1925

20-
26+
console.log(square(4)); // should print 16, does display correctly.

0 commit comments

Comments
 (0)