Skip to content

Commit 28c854e

Browse files
committed
changes to Sprint1 updated
1 parent 1304d1b commit 28c854e

18 files changed

Lines changed: 105 additions & 29 deletions

File tree

Sprint-1/2-mandatory-errors/0.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Currently trying to print the string "I was born in Bolton" but it isn't working...
22
// what's the error ?
33

4-
console.log(`I was born in ${cityOfBirth}`);
54
const cityOfBirth = "Bolton";
5+
console.log(`I was born in ${cityOfBirth}`);
6+
//const cityOfBirth = "Bolton";
67
//problem: we are trying to use the variable "cityOfBirth" before it has been declared and assigned a value. In JavaScript, variables declared with "const" or "let" cannot be accessed before they are declared. To fix this error, we need to declare and assign a value to "cityOfBirth" before we try to use it. So we would move the line "const cityOfBirth = "Bolton";" above the console.log statement.
14.3 KB
Binary file not shown.

Sprint-2/1-key-errors/0.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3+
//The code will throw an error because the variable 'str' is being redeclared inside the function, which is not allowed in JavaScript. The error message will likely indicate that 'str' has already been declared.
34

45
// call the function capitalise with a string input
56
// interpret the error message and figure out why an error is occurring
67

7-
function capitalise(str) {
8-
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
9-
return str;
10-
}
8+
//function capitalise(str) {
9+
//let str = `${str[0].toUpperCase()}${str.slice(1)}`;
10+
//return str;
11+
//}
1112

1213
// =============> write your explanation here
14+
//setup an new str variable inside the function called Newstr, which is assigned the value of the capitalised string. Then return Newstr instead of str to avoid the redeclaration error. Finally test using an assertion to check if the function is working as expected.
1315
// =============> write your new code here
16+
function capitalise(str) {
17+
let Newstr = `${str[0].toUpperCase()}${str.slice(1)}`;
18+
return Newstr;
19+
}
20+
let str = "hello";
21+
console.assert(capitalise(str) === "Hello");

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,25 @@
22

33
// Why will an error occur when this program runs?
44
// =============> write your prediction here
5-
5+
//The code will throw an error because the variable 'decimalNumber' is being redeclared inside the function, which is not allowed in JavaScript. The error message will likely indicate that 'decimalNumber' has already been declared.
66
// Try playing computer with the example to work out what is going on
77

8-
function convertToPercentage(decimalNumber) {
9-
const decimalNumber = 0.5;
10-
const percentage = `${decimalNumber * 100}%`;
8+
//function convertToPercentage(decimalNumber) {
9+
//const decimalNumber = 0.5;
10+
//const percentage = `${decimalNumber * 100}%`;
1111

12-
return percentage;
13-
}
12+
//return percentage;
13+
//}
1414

15-
console.log(decimalNumber);
15+
//console.log(decimalNumber);
1616

1717
// =============> write your explanation here
18-
18+
// define a new variable called percentage that is assigned the value of the decimal number multiplied by 100 and concatenated with the percentage symbol. Then return the percentage variable instead of trying to redeclare the decimalNumber variable. Finally test using an assertion to check if the function is working as expected.
1919
// Finally, correct the code to fix the problem
2020
// =============> write your new code here
21+
function convertToPercentage(decimalNumber) {
22+
const percentage = `${decimalNumber * 100}%`;
23+
return percentage;
24+
}
25+
console.assert(convertToPercentage(0.5) === "50%");
26+

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,24 @@
44
// this function should square any number but instead we're going to get an error
55

66
// =============> write your prediction of the error here
7-
8-
function square(3) {
9-
return num * num;
10-
}
7+
// The code will throw an error because the parameter '3' is not a valid variable name in JavaScript. The error message will likely indicate that '3' is an unexpected token or that it is not a valid identifier.
8+
//function square(3) {
9+
// return num * num;
10+
//}
1111

1212
// =============> write the error message here
13-
13+
//SyntaxError: Unexpected token '3'
1414
// =============> explain this error message here
1515

1616
// Finally, correct the code to fix the problem
1717

1818
// =============> write your new code here
1919

20+
function square(num) {
21+
return num * num;
22+
}
23+
let num = 3;
24+
console.log
25+
console.assert(square(3) === 9);
26+
2027

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

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

33
// =============> write your prediction here
4+
// The code will throw an error because the function 'multiply' does not return a value, so when it is called inside the template literal, it will return undefined. The error message will likely indicate that the result of multiplying 10 and 32 is undefined or that it cannot be used in a string context.
5+
//function multiply(a, b) {
6+
//console.log(a * b);
7+
//}
48

5-
function multiply(a, b) {
6-
console.log(a * b);
7-
}
8-
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

1111
// =============> write your explanation here
12-
12+
// The function 'multiply' is defined to take two parameters, 'a' and 'b', and it logs the product of 'a' and 'b' to the console. However, it does not return any value, which means that when it is called inside the template literal, it will return undefined. This is why we get an error when trying to use the result of the multiplication in a string context.
1313
// Finally, correct the code to fix the problem
1414
// =============> write your new code here
15+
function multiply(a, b) {
16+
return a * b;
17+
}
18+
19+
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3-
3+
// The code will throw an error because the function 'sum' does not return a value, so when it is called inside the template literal, it will return undefined. The error message will likely indicate that the result of adding 10 and 32 is undefined or that it cannot be used in a string context.
44
function sum(a, b) {
5-
return;
6-
a + b;
5+
return a + b;
76
}
87

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

1110
// =============> write your explanation here
11+
//
1212
// Finally, correct the code to fix the problem
1313
// =============> write your new code here

prep/12HourClock.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
function formatAs12HourClock(time) {
2+
const [hours, minutes] = time.split(":").map(Number);
3+
const ampm = hours >= 12 ? "pm" : "am";
4+
const formattedHours = hours % 12 || 12;
5+
return `${formattedHours.toString().padStart(2, "0")}:${minutes.toString().padStart(2, "0")} ${ampm}`;
6+
}
7+
let time = "23:00";
8+
//console.log(formatAs12HourClock(time));
9+
console.assert(formatAs12HourClock(time) === "11:00 pm");

prep/Agenda 14 Feb 26.pptx

3.04 MB
Binary file not shown.

0 commit comments

Comments
 (0)