Skip to content

Commit 4d8de06

Browse files
reviwing the content for updates and polishing my explanations
1 parent 1c37d58 commit 4d8de06

3 files changed

Lines changed: 27 additions & 21 deletions

File tree

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3-
//function capitalize will capitalise the first letter with index 0
4-
// and will append the sliced string from index 1 which is the second letter
3+
/*
4+
I predict the function will throw a SyntaxError as the variable str has already been declared in the function parameter
5+
function capitalize will capitalise the first letter with index 0
6+
and will append the sliced string from index 1 which is the second letter
7+
*/
58

6-
// call the function capitalise with a string input
9+
//call the function capitalise with a string input
710

8-
// interpret the error message and figure out why an error is occurring
9-
//syntax Error :identifier the variabel has already been declared.
10-
// As we can see the str variable has already been declared in the prameter of the function instead we just return the value
11-
// The Error message is
11+
// interpret the error message and figure out why an error is occurring :
12+
13+
/* syntax Error :identifier the variabel has already been declared.
14+
As we can see the str variable has already been declared in the prameter of the function instead we just return the value */
1215

1316
// function capitalise(str) {
1417
// let str = `${str[0].toUpperCase()}${str.slice(1)}`;
@@ -18,11 +21,11 @@
1821

1922

2023
// =============> write your explanation here
21-
22-
// =============> write your new code here
24+
/* syntax Error :identifier the variabel has already been declared.
25+
As we can see the str variable has already been declared in the prameter of the function instead we just return the value */
2326

2427
function capitalise(str) {
25-
return `${str[0].toUpperCase()}${str.slice(1)}`;
28+
return str[0].toUpperCase()+str.slice(1);
2629

2730
}
2831
capitalise("ebrahim");

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@
2020

2121

2222
// =============> write your explanation here
23-
//similar to the previous exercise where the variable decimal Number has already been declared in the parameter
24-
// and already is a local variable which can't be declared again
25-
//As the decimalNumber inside the function we can't print it using the console.log() as it has no power to the local scope
26-
//instead we can delete the second declaration and just leave the parameter as an input for the user which would be nicely work
27-
// Finally, correct the code to fix the problem
23+
/* The variable decimal Number has already been declared in the parameter
24+
and already is a local variable which can't be declared again causing a ReferenceError
25+
As the decimalNumber inside the function we can't print it using the console.log() as it has no power to the local scope
26+
instead we can delete the second declaration and just leave the parameter as an input for the user
27+
Finally, correct the code to fix the problem */
2828

2929
// =============> write your new code here
3030
function convertToPercentage(decimalNumber) {
3131
const percentage = `${decimalNumber * 100}%`;
32-
return percentage;
32+
return percentage;
3333
}
3434

3535
console.log(convertToPercentage(0.5));

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
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-
//The error might be accuring because the parameter can't be a number and should be a variable
7+
//I predict the funciton will throw a SyntaxEror as the perametters sould be valid variables like names or identifiers with upholding to the variable naming convention and in this case a number found
88

99
// function square(3) {
1010
// return num * num;
@@ -14,13 +14,16 @@
1414
//the Error is a syntax error: Unexpected number
1515

1616
// =============> explain this error message here
17-
// we can put a number or any argument when we call the number not when we shape it
17+
/* The function was givin a number as its perameter where in JS only allows varaible names and usnig a number causes a SyntaxError
18+
Also, the function was returning num*num where num is undefined causing a ReferenceError
19+
*/
1820

1921
// Finally, correct the code to fix the problem
20-
function square(num) {
21-
return num * num;
22-
}
2322

2423
// =============> write your new code here
2524

25+
function square(num) {
26+
return num * num;
27+
}
2628

29+
console.log(square(25));

0 commit comments

Comments
 (0)