Skip to content

Commit 20c57d3

Browse files
copmpleted_2-mandatory-debug
1 parent e4bcef4 commit 20c57d3

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

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

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

33
// =============> write your prediction here
4+
// missed "return". undefined output.
45

56
function multiply(a, b) {
67
console.log(a * b);
@@ -9,6 +10,12 @@ function multiply(a, b) {
910
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
1011

1112
// =============> write your explanation here
13+
//return — returns a value from a function to the outside
1214

1315
// Finally, correct the code to fix the problem
1416
// =============> write your new code here
17+
function multiply(a, b) {
18+
return a * b;
19+
}
20+
21+
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3+
// invalid syntax
34

45
function sum(a, b) {
56
return;
@@ -9,5 +10,11 @@ function sum(a, b) {
910
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
1011

1112
// =============> write your explanation here
13+
//if the code does not return anything, then the output is undefined
1214
// Finally, correct the code to fix the problem
1315
// =============> write your new code here
16+
function sum(a, b) {
17+
return a + b;
18+
}
19+
20+
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
// Predict the output of the following code:
44
// =============> Write your prediction here
5+
// the output is always going to be '3'
56

67
const num = 103;
78

@@ -15,10 +16,21 @@ 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
1822
// Explain why the output is the way it is
1923
// =============> write your explanation here
24+
// when the function is declared there is no parameters so in the body of function, num refers to global variable which has always the same value, so when we call the function arguments are ignored.
2025
// Finally, correct the code to fix the problem
2126
// =============> write your new code here
2227

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

0 commit comments

Comments
 (0)