You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Sprint-2/1-key-errors/1.js
+21-2Lines changed: 21 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -2,9 +2,10 @@
2
2
3
3
// Why will an error occur when this program runs?
4
4
// =============> write your prediction here
5
+
// When the JS executed the code, it will give 2 possible error 1 is decimalNumber is define inside the function and decimalNumber is undefined when using console.log
5
6
6
7
// Try playing computer with the example to work out what is going on
7
-
8
+
/*
8
9
function convertToPercentage(decimalNumber) {
9
10
const decimalNumber = 0.5;
10
11
const percentage = `${decimalNumber * 100}%`;
@@ -13,8 +14,26 @@ function convertToPercentage(decimalNumber) {
13
14
}
14
15
15
16
console.log(decimalNumber);
16
-
17
+
*/
17
18
// =============> write your explanation here
18
19
20
+
/*
21
+
For function convertToPercentage there are 1 error:
22
+
inside the function the decimalNumber parameter is being re-declare and given a fix value, this will give this function a
23
+
decimalNumber are ready defined.
24
+
25
+
Next is when we console.log the function instead of calling the function name and value we used the function parameter variable name
26
+
instead. This will give the error decimalNumber is undefined.
Copy file name to clipboardExpand all lines: Sprint-2/1-key-errors/2.js
+9-2Lines changed: 9 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -5,16 +5,23 @@
5
5
6
6
// =============> write your prediction of the error here
7
7
8
+
// For function square the variable inside the parameter will have a error, because number cant be used when name a variable and num variable is undefine.
9
+
/*
8
10
function square(3) {
9
11
return num * num;
10
12
}
11
-
13
+
*/
12
14
// =============> write the error message here
15
+
// SyntaxError: Unexpected number
13
16
14
17
// =============> explain this error message here
18
+
//Because number cant be used when name a variable.
The function multiply when is log into the terminal. we will receive a print out expression from
6
+
first console.log inside the function and undefined value from the string template inside the section console.log.
7
+
*/
4
8
9
+
/*
5
10
function multiply(a, b) {
6
11
console.log(a * b);
7
12
}
8
13
9
14
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
15
+
*/
10
16
11
17
// =============> write your explanation here
18
+
/*
19
+
First the function multiply have 2 parameter identifier a and b, the main purpose of this function is to multiply any argument that put
20
+
into the identifier a and b. Inside the the function is we have the function call console.log and nested inside is the expression from multiply of a and b.
21
+
However this will lead to error, since we need to return the expression(value) back to the function so it can be re used when call in a string template or other
22
+
function.
12
23
24
+
*/
13
25
// Finally, correct the code to fix the problem
14
26
// =============> write your new code here
27
+
28
+
functionmultiply(a,b){
29
+
returna*b;
30
+
}
31
+
32
+
console.log(`The result of multiplying 10 and 32 is ${multiply(10,32)}`);
0 commit comments