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
// =============> console.log will print the result because log()will write the message to the console.
4
+
//
4
5
5
6
functionmultiply(a,b){
6
7
console.log(a*b);
7
8
}
8
9
9
10
console.log(`The result of multiplying 10 and 32 is ${multiply(10,32)}`);
10
11
11
-
// =============> write your explanation here
12
-
12
+
// =============> When testing the code in Node.js, the output was 320 without the message because it was undefined "The result of multiplying 10 and 32 is undefined".
13
+
//we need to use return to store the result then print it out.
13
14
// Finally, correct the code to fix the problem
14
-
// =============> write your new code here
15
+
// =============> // Corrected Code:
16
+
functionmultiply(a,b){
17
+
returna*b;// Use 'return' instead of 'console.log'
18
+
}
19
+
console.log(`The result of multiplying 10 and 32 is ${multiply(10,32)}`);
// =============> I predict that the code might not work because I am declaring num outside the function also I am giving num a constant value means it will always be 103
5
5
6
6
constnum=103;
7
7
@@ -14,11 +14,19 @@ console.log(`The last digit of 105 is ${getLastDigit(105)}`);
14
14
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
15
15
16
16
// Now run the code and compare the output to your prediction
17
-
// =============> write the output here
17
+
// =============> the code worked but the answer was 3 i predicted an error message.
18
18
// Explain why the output is the way it is
19
-
// =============> write your explanation here
19
+
// =============> the output was 3 because at the beginning it we declared that num value as 103
20
20
// Finally, correct the code to fix the problem
21
-
// =============> write your new code here
21
+
// =============> corrected code is running the code without giving num any value and add num in the function
22
+
23
+
functiongetLastDigit(num){
24
+
returnnum.toString().slice(-1);
25
+
}
26
+
27
+
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
28
+
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
29
+
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
22
30
23
31
// This program should tell the user the last digit of each number.
24
-
// Explain why getLastDigit is not working properly - correct the problem
32
+
// Explain why getLastDigit is not working properly - it was not working at the start because every time we run the code would slice the last number of the 103 because we declared num as a constant with value 103
0 commit comments