Skip to content

Commit f97b348

Browse files
committed
updated files in key errors and mandatory-debug folders
1 parent d28242a commit f97b348

6 files changed

Lines changed: 58 additions & 18 deletions

File tree

‎Sprint-3/1-key-errors/0.js‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Predict and explain first...
2-
// =============> write your prediction here
2+
// It would fail at line 2 with either syntax or reference errors =============> write your prediction here
33

44
// call the function capitalise with a string input
55
// interpret the error message and figure out why an error is occurring
@@ -8,6 +8,13 @@ function capitalise(str) {
88
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
99
return str;
1010
}
11+
console.log(capitalise("beautiful"));
1112

12-
// =============> write your explanation here
13+
// function is assigned 2 arguments/values=============> write your explanation here
1314
// =============> write your new code here
15+
16+
function capitalise(str) {
17+
str = `${str[0].toUpperCase()}${str.slice(1)}`;
18+
return str;
19+
}
20+
console.log(capitalise("beautiful"));

‎Sprint-3/1-key-errors/1.js‎

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

33
// Why will an error occur when this program runs?
4-
// =============> write your prediction here
4+
// decimalNumber is called twice=============> write your prediction here
55

66
// Try playing computer with the example to work out what is going on
77

@@ -14,7 +14,17 @@ function convertToPercentage(decimalNumber) {
1414

1515
console.log(decimalNumber);
1616

17-
// =============> write your explanation here
17+
// decimalNumber has been declared as a function and a variable within function scope=============> write your explanation here
18+
//Removing const decimalNumber still returns Syntax error if still within the function scope so it's not restricted to the function
1819

1920
// Finally, correct the code to fix the problem
2021
// =============> write your new code here
22+
23+
function convertToPercentage(decimalNumber) {
24+
const percentage = `${decimalNumber * 100}%`;
25+
26+
return percentage;
27+
}
28+
const decimalNumber = 0.5;
29+
30+
console.log(decimalNumber);

‎Sprint-3/1-key-errors/2.js‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1-
21
// Predict and explain first BEFORE you run any code...
32

43
// this function should square any number but instead we're going to get an error
54

6-
// =============> write your prediction of the error here
5+
// Unidentified function error due to a random number =============> write your prediction of the error here
76

8-
function square(3) {
9-
return num * num;
10-
}
7+
//function square(num) {
8+
//return square = num * num;
9+
//}
1110

12-
// =============> write the error message here
11+
// Syntax errorError Unexpected number.=============> write the error message here
1312

14-
// =============> explain this error message here
13+
// Means Function identifier should be a name not a number =============> explain this error message here
1514

1615
// Finally, correct the code to fix the problem
1716

1817
// =============> write your new code here
1918

20-
19+
function square(num) {
20+
return (square = num * num);
21+
}
22+
console.log(square(3));

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

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

3-
// =============> write your prediction here
3+
// Code will fail because a , b are not declared values or double function values=============> write your prediction here
44

55
function multiply(a, b) {
66
console.log(a * b);
@@ -9,6 +9,12 @@ function multiply(a, b) {
99
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
1010

1111
// =============> write your explanation here
12-
12+
//The 2nd console log returned value value is undefined. I have added a return function to output the multiply value.
1313
// Finally, correct the code to fix the problem
1414
// =============> write your new code here
15+
function multiply(a, b) {
16+
console.log(a * b);
17+
return a * b;
18+
}
19+
20+
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3+
// I think code will run without an error although not entirely sure what the empty return; will return
34

45
function sum(a, b) {
56
return;
@@ -8,6 +9,10 @@ function sum(a, b) {
89

910
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
1011

11-
// =============> write your explanation here
12+
// Maybe that unassigned return; may cause the code not to run fully =============> write your explanation here
1213
// Finally, correct the code to fix the problem
1314
// =============> write your new code here
15+
function sum(a, b) {
16+
return a + b;
17+
}
18+
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,33 @@
22

33
// Predict the output of the following code:
44
// =============> Write your prediction here
5-
6-
const num = 103;
5+
//I think const being declared before function may cause a problem on returning num value (line 10)
76

87
function getLastDigit() {
8+
const num = 103;
99
return num.toString().slice(-1);
1010
}
11-
1211
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
1312
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
1413
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
1514

1615
// Now run the code and compare the output to your prediction
1716
// =============> write the output here
17+
// My prediction was close regarding line 10 as the value of num is not returned.
1818
// Explain why the output is the way it is
1919
// =============> write your explanation here
20+
// The code has returned 3 as the last digit for all provided numbers because num value is restricted to 103 as value and can't be used outside the function
21+
// Also function getLastDigit() has no parameter set
2022
// Finally, correct the code to fix the problem
2123
// =============> write your new code here
2224

25+
function getLastDigit(num) {
26+
return num.toString().slice(-1);
27+
}
28+
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
29+
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
30+
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
31+
2332
// This program should tell the user the last digit of each number.
2433
// Explain why getLastDigit is not working properly - correct the problem
34+
// getLastDigit was no working as variable num was taking precedence

0 commit comments

Comments
 (0)