Skip to content

Commit da042e4

Browse files
author
kohanman
committed
Sprint 2 | Coursework 2.2
1 parent 64baf41 commit da042e4

File tree

1 file changed

+21
-9
lines changed
  • Sprint-2/2-mandatory-debug

1 file changed

+21
-9
lines changed

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

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,35 @@
22

33
// Predict the output of the following code:
44
// =============> Write your prediction here
5+
//will log "the last digit ...3" for all three lines
56

6-
const num = 103;
7+
// const num = 103;
78

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

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

1617
// Now run the code and compare the output to your prediction
1718
// =============> write the output here
19+
// The last digit of 42 is 3
20+
// The last digit of 105 is 3
21+
// The last digit of 806 is 3
22+
1823
// Explain why the output is the way it is
1924
// =============> write your explanation here
25+
//cos the getLastDigit function is returning from the const num = 103, rather than its parameter
26+
2027
// Finally, correct the code to fix the problem
2128
// =============> write your new code here
2229

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

0 commit comments

Comments
 (0)