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-3/2-mandatory-debug/2.js
+13-13Lines changed: 13 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -5,13 +5,13 @@
5
5
6
6
constnum=103;
7
7
8
-
functiongetLastDigit(){
9
-
returnnum.toString().slice(-1);
10
-
}
8
+
// function getLastDigit() {
9
+
// return num.toString().slice(-1);
10
+
// }
11
11
12
-
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
13
-
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
14
-
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
12
+
// console.log(`The last digit of 42 is ${getLastDigit(42)}`);
13
+
// console.log(`The last digit of 105 is ${getLastDigit(105)}`);
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
17
// =============> write the output here :output
@@ -20,16 +20,16 @@ console.log(`The last digit of 806 is ${getLastDigit(806)}`);
20
20
The last digit of 806 is 3
21
21
*/
22
22
// Explain why the output is the way it is
23
-
// =============> write your explanation here: The funtion return on single value (3) no matter what parameter is passed to it because the function does not take any parameters and it is using the gobal variable num which is set to 103. So the last digit of 103 is always 3.
23
+
// =============> write your explanation here: The funtion return one single value (3) no matter what parameter is passed to it because the function does not take any parameters and it is using the gobal variable num which is set to 103. So the last digit of 103 is always 3.
24
24
// Finally, correct the code to fix the problem
25
25
// =============> write your new code here
26
26
27
-
// function getLastDigit(num) {
28
-
// return num.toString().slice(-1);
29
-
// }
30
-
// console.log(`The last digit of 42 is ${getLastDigit(42)}`);
31
-
// console.log(`The last digit of 105 is ${getLastDigit(105)}`);
32
-
// console.log(`The last digit of 806 is ${getLastDigit(806)}`);
27
+
functiongetLastDigit(num){
28
+
returnnum.toString().slice(-1);
29
+
}
30
+
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
31
+
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
32
+
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
33
33
34
34
// This program should tell the user the last digit of each number.
35
35
// Explain why getLastDigit is not working properly - correct the problem : The first declaration of num as constent should be removed and the function getLastDigit should take a parameter num to return the last digit of the number passed to it.
0 commit comments