Skip to content

Commit e4bcef4

Browse files
completed-1-key-errors
1 parent 124ae45 commit e4bcef4

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,10 @@ function capitalise(str) {
99
return str;
1010
}
1111

12-
// =============> write your explanation here
12+
// =============> write your explanation here
13+
// It leeds to an error declaring the same variable name more than 1 time.
14+
// It also can confuse reassigning the variable str. it is better to remove it or made up a new one.
1315
// =============> write your new code here
16+
function capitalise(str) {
17+
return `${str[0].toUpperCase()}${str.slice(1)}`;
18+
}

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

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

33
// Why will an error occur when this program runs?
4-
// =============> write your prediction here
5-
4+
// decimalNumber was already declared on the line 8. it leads to an error declaring it the second time on the line 9.
5+
// line 15 is in global scope and tries output value of the local variable from inside of the function.
66
// Try playing computer with the example to work out what is going on
77

88
function convertToPercentage(decimalNumber) {
@@ -14,7 +14,13 @@ function convertToPercentage(decimalNumber) {
1414

1515
console.log(decimalNumber);
1616

17-
// =============> write your explanation here
17+
// i will declare the decimalNumber variable before the function and call the function. i would also removed the percentage variable because it doesn't make anything useful in this piece of code.
1818

1919
// Finally, correct the code to fix the problem
20-
// =============> write your new code here
20+
const decimalNumber = 0.5;
21+
function convertToPercentage(decimalNumber) {
22+
return `${decimalNumber * 100}%`;
23+
}
24+
25+
console.log(convertToPercentage(decimalNumber))
26+

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,22 @@
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+
//reference error (not existing variable (num))
78

89
function square(3) {
910
return num * num;
1011
}
1112

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

1416
// =============> explain this error message here
17+
//When we declare a function, it is expected that the parameter names will be in brackets.
1518

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

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

0 commit comments

Comments
 (0)