Skip to content

Commit 93486c9

Browse files
author
Arthur
committed
global frame and variable
1 parent fedf840 commit 93486c9

1 file changed

Lines changed: 26 additions & 11 deletions

File tree

  • Sprint-2/2-mandatory-debug

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

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
// Predict and explain first...
21

3-
// Predict the output of the following code:
4-
// =============> Write your prediction here
2+
The const should not be put into the global frame.
3+
if it is set in the global frame, this will result in a single result:3,
4+
no matter which variables you put in later.
5+
6+
The variable insides should have num to match the function expression.
7+
8+
9+
My prediction of the result will be all in 3.
510

611
const num = 103;
712

@@ -13,12 +18,22 @@ console.log(`The last digit of 42 is ${getLastDigit(42)}`);
1318
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
1419
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
1520

16-
// Now run the code and compare the output to your prediction
17-
// =============> write the output here
18-
// Explain why the output is the way it is
19-
// =============> write your explanation here
20-
// Finally, correct the code to fix the problem
21-
// =============> write your new code here
2221

23-
// This program should tell the user the last digit of each number.
24-
// Explain why getLastDigit is not working properly - correct the problem
22+
23+
yes the output is all in 3, because the reason are above .
24+
25+
26+
27+
... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
28+
29+
function getLastDigit(num) {
30+
return num.toString().slice(-1);
31+
}
32+
33+
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
34+
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
35+
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
36+
37+
38+
After we delete the global frame and put in the variable, we see
39+
the result now shows three different digit number.

0 commit comments

Comments
 (0)