Skip to content

Commit 47f65d6

Browse files
feat: complete sprint-3
1 parent cdb761b commit 47f65d6

14 files changed

Lines changed: 166 additions & 268 deletions

File tree

‎Form-Controls/README.md‎

Lines changed: 0 additions & 72 deletions
This file was deleted.

‎Form-Controls/index.css‎

Lines changed: 0 additions & 47 deletions
This file was deleted.

‎Form-Controls/index.html‎

Lines changed: 0 additions & 97 deletions
This file was deleted.

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
// Predict and explain first...
2-
// =============> write your prediction here
2+
// It will make the first letter in the string input capitalised.
33

44
// call the function capitalise with a string input
55
// interpret the error message and figure out why an error is occurring
6+
// "SyntaxError: Identifier 'str' has already been declared"
7+
8+
// capitalise("matthaus enjoys foood.")
9+
10+
// function capitalise(str) {
11+
// let str = `${str[0].toUpperCase()}${str.slice(1)}`;
12+
// return str;
13+
// }
14+
15+
// The error is thrown by declaring the 'str' variable again in the function with 'let' which causes it throw the SyntaxError, as it is already been declared.
16+
17+
capitalise("matthaus enjoys food")
618

719
function capitalise(str) {
8-
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
9-
return str;
20+
return `${str[0].toUpperCase()}${str.slice(1)}`;
1021
}
1122

12-
// =============> write your explanation here
13-
// =============> write your new code here
23+
console.log(capitalise("Matthaus enjoys food"));

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

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
11
// Predict and explain first...
2+
// It will give you a percentage of 50% using the function by multiplying the 'decimalNumber' by 100 for the 'percentage' variables.
23

34
// Why will an error occur when this program runs?
4-
// =============> write your prediction here
5+
// It will be a syntaxError because the 'decimalNumber' is already called in the function parameter.
56

67
// Try playing computer with the example to work out what is going on
78

9+
// function convertToPercentage(decimalNumber) {
10+
// const decimalNumber = 0.5;
11+
// const percentage = `${decimalNumber * 100}%`;
12+
13+
// return percentage;
14+
// }
15+
16+
// console.log(decimalNumber);
17+
18+
// decimalNumber in console.log isn't a defined number in the functions parameter now so it will return back as NaN "Not a Number", by adding '0.05' to the console.log it now has a number to calculate the percentage to
19+
20+
// Finally, correct the code to fix the problem
21+
22+
823
function convertToPercentage(decimalNumber) {
9-
const decimalNumber = 0.5;
1024
const percentage = `${decimalNumber * 100}%`;
1125

1226
return percentage;
13-
}
14-
15-
console.log(decimalNumber);
1627

17-
// =============> write your explanation here
28+
}
1829

19-
// Finally, correct the code to fix the problem
20-
// =============> write your new code here
30+
console.log(convertToPercentage(0.5))

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11

22
// Predict and explain first BEFORE you run any code...
3+
// The function won't return be able to return the value to the caller, due to the expression not being assigned.
34

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

6-
// =============> write your prediction of the error here
7+
// The expression will return as unexpected number in the console log
78

8-
function square(3) {
9-
return num * num;
10-
}
9+
// function square(3) {
10+
// return num * num;
11+
// }
1112

12-
// =============> write the error message here
13+
// SyntaxError: Unexpected number
1314

14-
// =============> explain this error message here
15+
// The parameter set by the function isn't attached to the num value of the return, so the return doesn't have a value to work with
1516

1617
// Finally, correct the code to fix the problem
1718

18-
// =============> write your new code here
19+
function square(num) {
20+
return num * num;
21+
}
22+
23+
console.log(square(3));
24+
1925

2026

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

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

3-
// =============> write your prediction here
3+
// There is no return in the function, the wrong use of console.log is being used, therefore the function isn't being closed and only is the console.log being logged twice, causing the function's parameters to be defined by the return.
44

5-
function multiply(a, b) {
6-
console.log(a * b);
7-
}
5+
// function multiply(a, b) {
6+
// console.log(a * b);
7+
// }
88

9-
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
9+
// console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
1010

11-
// =============> write your explanation here
11+
// The instead of console.log being used in the functions expression, there should be a return.
1212

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

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
// Predict and explain first...
2-
// =============> write your prediction here
2+
// By using the semi-colon after the return, this is closing off the function and leaving the parameters as undefined, causing the console.log state that the parameters are undefined.
33

4+
// function sum(a, b) {
5+
// return;
6+
// a + b;
7+
// }
8+
9+
// console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
10+
11+
// by using the semi-colon after the return, and having the parameters put into a separate line, the return can't define the parameters of the function.
12+
// Finally, correct the code to fix the problem
413
function sum(a, b) {
5-
return;
6-
a + b;
14+
return a + b;
715
}
816

917
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
10-
11-
// =============> write your explanation here
12-
// Finally, correct the code to fix the problem
13-
// =============> write your new code here

0 commit comments

Comments
 (0)