Skip to content

Commit bada0ad

Browse files
committed
2-mandatory-degub 2.js
Answered questions and fixed the code as requested.
1 parent 49726c9 commit bada0ad

1 file changed

Lines changed: 25 additions & 8 deletions

File tree

  • Sprint-3/2-mandatory-debug

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

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,41 @@
11
// Predict and explain first...
22

3-
// Predict the output of the following code:
3+
// Predict the output of the following code:
44
// =============> Write your prediction here
5+
// num is made to be 103, so every .log will have the answer being 3.
6+
// function getLasDigit() has no parameter set, so the number set
57

6-
const num = 103;
8+
// const num = 103;
79

8-
function getLastDigit() {
9-
return num.toString().slice(-1);
10-
}
10+
// function getLastDigit() {
11+
// return num.toString().slice(-1);
12+
// }
1113

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)}`);
14+
// console.log(`The last digit of 42 is ${getLastDigit(42)}`);
15+
// console.log(`The last digit of 105 is ${getLastDigit(105)}`);
16+
// console.log(`The last digit of 806 is ${getLastDigit(806)}`);
1517

1618
// Now run the code and compare the output to your prediction
1719
// =============> write the output here
20+
// The last digit of 42 is 3
21+
// The last digit of 105 is 3
22+
// The last digit of 806 is 3
23+
1824
// Explain why the output is the way it is
1925
// =============> write your explanation here
26+
// const num = 103 is making it that num is always 103, also function getLastDigit() has no parameter set.
27+
// This makes it that the value from teh console.log() wont be used.
28+
2029
// Finally, correct the code to fix the problem
2130
// =============> write your new code here
2231

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

0 commit comments

Comments
 (0)