Skip to content

Commit e67a022

Browse files
committed
1-key-errors sprint3 completed
1 parent d0828f2 commit e67a022

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

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

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

33
// Why will an error occur when this program runs?
4-
// =============> write your prediction here
4+
// =============> We will get a SyntaxError as decimalNumber has already been declared as a parameter of the function.
55

66
// Try playing computer with the example to work out what is going on
77

8+
/*
89
function convertToPercentage(decimalNumber) {
910
const decimalNumber = 0.5;
1011
const percentage = `${decimalNumber * 100}%`;
1112
1213
return percentage;
1314
}
1415
15-
console.log(decimalNumber);
16+
console.log(decimalNumber); */
1617

1718
// =============> write your explanation here
19+
// We don't need to redeclare decimalNumber as it's value comes from function parameter,
20+
// also console.log wont work as decimalNumber is only created inside the function.
1821

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

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,22 @@
33

44
// this function should square any number but instead we're going to get an error
55

6-
// =============> write your prediction of the error here
6+
// =============> SyntaxError because function parameter must be a name not a number or value. The error occurs because 3 is a number.
77

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

12-
// =============> write the error message here
13+
// =============> SyntaxError: Unexpected number
1314

14-
// =============> explain this error message here
15+
// =============> This error message is cause by trying to assign a number as a parameter, a parameter needs to be identifier such as num.
1516

1617
// Finally, correct the code to fix the problem
1718

1819
// =============> write your new code here
19-
20+
function square(num) {
21+
return num * num;
22+
}
23+
console.log(square(5))
2024

0 commit comments

Comments
 (0)