Skip to content

Commit 0a40c26

Browse files
committed
completed 2-mandatory-debug/2.js
1 parent 1125393 commit 0a40c26

1 file changed

Lines changed: 28 additions & 10 deletions

File tree

  • Sprint-2/2-mandatory-debug

Sprint-2/2-mandatory-debug/2.js

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,41 @@
22

33
// Predict the output of the following code:
44
// =============> Write your prediction here
5-
6-
const num = 103;
7-
8-
function getLastDigit() {
9-
return num.toString().slice(-1);
10-
}
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)}`);
5+
/* we have a variable that is declared in the global scope, and in the function we are returning the variable -num, we also
6+
do not have a parameter for the function, but we call the function passing it an argument. we might get an argument error
7+
*
8+
*
9+
* */
10+
// const num = 103;
11+
//
12+
// function getLastDigit() {
13+
// return num.toString().slice(-1);
14+
// }
15+
//
16+
// console.log(`The last digit of 42 is ${getLastDigit(42)}`);
17+
// console.log(`The last digit of 105 is ${getLastDigit(105)}`);
18+
// console.log(`The last digit of 806 is ${getLastDigit(806)}`);
1519

1620
// Now run the code and compare the output to your prediction
1721
// =============> write the output here
22+
// The last digit of 42 is 3
23+
// The last digit of 105 is 3
24+
// The last digit of 806 is 3
25+
1826
// Explain why the output is the way it is
1927
// =============> write your explanation here
28+
/*
29+
* The function does not have a parameter, so the arguments are ignored and the function instead uses the global variable
30+
* */
2031
// Finally, correct the code to fix the problem
2132
// =============> write your new code here
2233

34+
function getLastDigit(num) {
35+
return num.toString().slice(-1);
36+
}
37+
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
38+
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
39+
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
40+
2341
// This program should tell the user the last digit of each number.
2442
// Explain why getLastDigit is not working properly - correct the problem

0 commit comments

Comments
 (0)