Skip to content

Commit 795eeb5

Browse files
committed
sprint 2
1 parent d0d959c commit 795eeb5

12 files changed

Lines changed: 39 additions & 164 deletions

File tree

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

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3-
// you will get an error becuase srt has alredy been declared
4-
53

64
// call the function capitalise with a string input
75
// interpret the error message and figure out why an error is occurring
86

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

1412
// =============> write your explanation here
15-
//let str = `${str[0].toUpperCase()}${str.slice(1)}`;
16-
// ^
17-
18-
//SyntaxError: Identifier 'str' has already been declared
1913
// =============> write your new code here
20-
function capitalise(str) {
21-
let strTwo = `${str[0].toUpperCase()}${str.slice(1)}`;
22-
return str;
23-
}

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

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

33
// Why will an error occur when this program runs?
4-
// the veriable decimalNumber has already been declared
5-
6-
74
// =============> write your prediction here
85

96
// Try playing computer with the example to work out what is going on
107

11-
/*function convertToPercentage(decimalNumber) {
8+
function convertToPercentage(decimalNumber) {
129
const decimalNumber = 0.5;
1310
const percentage = `${decimalNumber * 100}%`;
1411

1512
return percentage;
1613
}
1714

18-
console.log(decimalNumber);*/
15+
console.log(decimalNumber);
1916

2017
// =============> write your explanation here
2118

22-
2319
// Finally, correct the code to fix the problem
2420
// =============> write your new code here
25-
function convertToPercentage(decimalNumber) {
26-
decimalNumber = 0.5;
27-
const percentage = `${decimalNumber * 100}%`;
28-
return percentage;
29-
}

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

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,19 @@
22
// Predict and explain first BEFORE you run any code...
33

44
// this function should square any number but instead we're going to get an error
5-
// there is nothing con nectimng the 3 to the variable num
5+
66
// =============> write your prediction of the error here
77

8-
/*function square(3) {
8+
function square(3) {
99
return num * num;
1010
}
11-
*/
12-
// =============> write the error message here
13-
//function square(3) {
14-
// ^
1511

16-
//SyntaxError: Unexpected number
12+
// =============> write the error message here
1713

1814
// =============> explain this error message here
19-
// it was expecting a variable not a number
2015

2116
// Finally, correct the code to fix the problem
2217

2318
// =============> write your new code here
2419

2520

26-
function square(num) {
27-
num = 3;
28-
return num * num;
29-
}
30-
console.log(square());

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

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

3-
// =============> write your prediction here it should print "The result of multiplying 10 and 32 is 320"
3+
// =============> write your prediction here
44

55
function multiply(a, b) {
66
console.log(a * b);

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3-
//i dont think it will give an answer becuse the semi-colon is after return
4-
/*function sum(a, b) {
3+
4+
function sum(a, b) {
55
return;
66
a + b;
77
}
88

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

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

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,24 @@
11
// Predict and explain first...
2-
//
2+
33
// Predict the output of the following code:
4-
// =============> Write your prediction here i thing this one will work
4+
// =============> Write your prediction here
55

6-
/*const num = 103;
6+
const num = 103;
77

88
function getLastDigit() {
99
return num.toString().slice(-1);
1010
}
1111

1212
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
1313
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
14-
console.log(`The last digit of 806 is ${getLastDigit(806)}`);*/
14+
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
1515

1616
// Now run the code and compare the output to your prediction
1717
// =============> write the output here
18-
// i was incorrect the const at the top makes them all come out as 3
1918
// Explain why the output is the way it is
2019
// =============> write your explanation here
21-
// the constant can't be changed by the code block and num needs to be part of the function
2220
// Finally, correct the code to fix the problem
2321
// =============> write your new code here
2422

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

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

Lines changed: 5 additions & 2 deletions
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-
// return the BMI of someone based off their weight and height
19-
}
18+
let heightsq = height * height;
19+
return weight/heightsq;
20+
// return the BMI of someone based off their weight and height
21+
}
22+
console.log(calculateBMI(30, 10));

Sprint-2/3-mandatory-implement/2-cases.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,10 @@
1414
// You will need to come up with an appropriate name for the function
1515
// Use the MDN string documentation to help you find a solution
1616
// This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase
17+
18+
function SNAKE_CASE (mesasge){
19+
let snake = mesasge.replace(/ /g,"_");
20+
let upper = snake.toUpperCase();
21+
return upper;
22+
}
23+
console.log(SNAKE_CASE("hello there"));

Sprint-2/3-mandatory-implement/3-to-pounds.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,14 @@
44
// You will need to declare a function called toPounds with an appropriately named parameter.
55

66
// You should call this function a number of times to check it works for different inputs
7+
8+
function toPounds(penceString) {
9+
let penceStringWithoutTrailingP = penceString.replace( /[^1-9]/g, ""); //39772
10+
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); //39772
11+
const pounds = paddedPenceNumberString.substring( 0, paddedPenceNumberString.length - 2 ); // 397
12+
const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2)
13+
.padEnd(2, "0"); // 72
14+
return ${pounds}.${pence}`; // 397.72
15+
16+
}
17+
console.log(toPounds("397d72p"));

Sprint-2/4-mandatory-interpret/time-format.js

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

0 commit comments

Comments
 (0)