Skip to content

Commit 03ff341

Browse files
committed
const num removed
1 parent 8b3c3ff commit 03ff341

1 file changed

Lines changed: 32 additions & 7 deletions

File tree

  • Sprint-3/2-mandatory-debug

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

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,49 @@
11
// Predict and explain first...
2+
// we want to get the last digit of the number value 103
23

34
// Predict the output of the following code:
5+
//I think it will give us the wrong answer due to not specifying the actual result of what we want which is the lastDigit.
6+
47
// =============> Write your prediction here
58

6-
const num = 103;
9+
// const num = 103;
710

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

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

1619
// Now run the code and compare the output to your prediction
20+
21+
//This is the answer that i received , which is different from my initial thought.
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+
1726
// =============> write the output here
1827
// Explain why the output is the way it is
28+
//the output is the same for all three due to the function always using the value 103.
29+
1930
// =============> write your explanation here
31+
// By creating a constant to the value of 103 the number will always calculate the const. and this is, is not what the function wants us to do, so we would have to remove it.
32+
//function -getLastDigit don't have a parameters which means that the other three values 42, 105, 806 will not be received by the function.
33+
//this means we need to give the function a parameter.
34+
//numToString changes the number into a string, this is so we can use the .slice() method.
35+
//.slice(-1) will give us the last character.
36+
2037
// Finally, correct the code to fix the problem
2138
// =============> write your new code here
2239

40+
function getLastDigit(num) {
41+
return num.toString().slice(-1);
42+
}
43+
44+
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
45+
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
46+
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
47+
2348
// This program should tell the user the last digit of each number.
2449
// Explain why getLastDigit is not working properly - correct the problem

0 commit comments

Comments
 (0)