Skip to content

Commit a15ff43

Browse files
removed double variable declaration inside the function
1 parent c2530c2 commit a15ff43

File tree

3 files changed

+15160
-13
lines changed

3 files changed

+15160
-13
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ function capitalise(str) {
1414
// but it is being accessed outside the function.
1515

1616
// =============> write your new code here:
17-
// function capitalise(str) {
18-
// let newStr = `${str[0].toUpperCase()}${str.slice(1)}`;
19-
// return newStr;
20-
// }
21-
// let newStr = capitalise("hello");
22-
// console.log(newStr);
17+
function capitalise(str) {
18+
let newStr = `${str[0].toUpperCase()}${str.slice(1)}`;
19+
return newStr;
20+
}
21+
let newStr = capitalise("hello");
22+
console.log(newStr);

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
1-
// Predict and explain first...
1+
// Predict and explain first: Decimalnumber is already declared as a parameter of the function convertToPercentage,
2+
// so when we try to declare it again inside the function, it will give an error.
23

34
// Why will an error occur when this program runs?
4-
// =============> write your prediction here
5+
// =============> write your prediction here : The error will occur because we are trying to declare a variable with the same name as the parameter of the function.
56

67
// Try playing computer with the example to work out what is going on
78

89
function convertToPercentage(decimalNumber) {
9-
const decimalNumber = 0.5;
10+
1011
const percentage = `${decimalNumber * 100}%`;
1112

1213
return percentage;
1314
}
1415

15-
console.log(decimalNumber);
16+
console.log(convertToPercentage(0.5));
1617

17-
// =============> write your explanation here
18+
// =============> write your explanation here : I removed the variable variation inside the function and directly calculated the percentage.
1819

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

0 commit comments

Comments
 (0)