Skip to content

Commit 7dec005

Browse files
coursework
1 parent b31a586 commit 7dec005

7 files changed

Lines changed: 60 additions & 18 deletions

File tree

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
// Predict and explain first...
2-
// =============> write your prediction here
3-
4-
// call the function capitalise with a string input
2+
// =============> We use a string template when we want to join different character sets together but by casing the first letter
3+
// to uppercase we're assuming that it is formed of letters
54
// interpret the error message and figure out why an error is occurring
65

76
function capitalise(str) {
87
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
98
return str;
109
}
1110

12-
// =============> write your explanation here
13-
// =============> write your new code here
11+
// he error message says 'str' has already been declared so we can use another name for our
12+
//output to solve that error we change the output variable name
13+
// function capitalise(str) {
14+
// let str = `${str[0].toUpperCase()}${str.slice(1)}`;
15+
// return str;
16+
//}

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

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

33
// Why will an error occur when this program runs?
4-
// =============> write your prediction here
4+
// The parameter is a constant which means the program will output the same thing everytime,
5+
//and would give an error message saying it has been declared if run.
56

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

@@ -10,11 +11,18 @@ function convertToPercentage(decimalNumber) {
1011
const percentage = `${decimalNumber * 100}%`;
1112

1213
return percentage;
14+
15+
console.log(decimalNumber);
1316
}
17+
// =============> Our parameter has already been declared which is why the program is resulting in an error
1418

15-
console.log(decimalNumber);
19+
// Finally, correct the code to fix the problem
20+
// function convertToPercentage(decimalNumber) {
21+
// const decimalNumber1 = 0.5;
22+
//const percentage = `${decimalNumber1 * 100}%`;
1623

17-
// =============> write your explanation here
24+
// return percentage;
25+
// console.log(decimalNumber1);
26+
//}
1827

19-
// Finally, correct the code to fix the problem
20-
// =============> write your new code here
28+
//

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

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

22
// Predict and explain first BEFORE you run any code...
3-
3+
//We are going to get an error because an integer cannot be a parameter, it has to be a variable.
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+
//syntaxERror, identifier cannot be an integer
78

89
function square(3) {
910
return num * num;
1011
}
1112

1213
// =============> write the error message here
14+
// Uncaught SyntaxError SyntaxError: Unexpected number
1315

1416
// =============> explain this error message here
15-
17+
//The program was expecting a function parameter but got a number instead
1618
// Finally, correct the code to fix the problem
1719

1820
// =============> write your new code here
21+
//function square(num) {
22+
// return num * num;
23+
//}
1924

2025

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

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

33
// =============> write your prediction here
4-
4+
//This won't work because we are not returning anything.
5+
56
function multiply(a, b) {
67
console.log(a * b);
78
}
@@ -11,4 +12,9 @@ console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
1112
// =============> write your explanation here
1213

1314
// Finally, correct the code to fix the problem
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)}`);
1420
// =============> write your new code here

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+
//This won't work because of a syntax error, return a+b should be on a single line and not on separate lines
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+
// The sum of a + b is undefined because we are not returning any value
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: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// Predict and explain first...
22

33
// Predict the output of the following code:
4-
// =============> Write your prediction here
4+
// =============> Write your prediction
5+
//It should output string cannot be accessed because we are using normal brackets instead of square brackets
56

67
const num = 103;
78

@@ -14,11 +15,20 @@ console.log(`The last digit of 105 is ${getLastDigit(105)}`);
1415
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
1516

1617
// Now run the code and compare the output to your prediction
17-
// =============> write the output here
18+
// =============>The output was 3 for all instead of the last digit of each number.
19+
//
1820
// Explain why the output is the way it is
19-
// =============> write your explanation here
21+
// =============> This is because we already declared the num variable as a constant
2022
// Finally, correct the code to fix the problem
21-
// =============> write your new code here
23+
// =============> write your new code here
2224

2325
// This program should tell the user the last digit of each number.
2426
// Explain why getLastDigit is not working properly - correct the problem
27+
//There was no parameter so the function wasn't running properly.
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)}`);

Sprint-2/3-mandatory-implement/1-bmi.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,8 @@
1515
// It should return their Body Mass Index to 1 decimal place
1616

1717
function calculateBMI(weight, height) {
18+
let bmi = weight / height*height;
19+
return bmi;
1820
// return the BMI of someone based off their weight and height
19-
}
21+
}
22+
console.log(`Your BMI is ${bmi}`)

0 commit comments

Comments
 (0)