Skip to content

Commit 22f84a7

Browse files
fixed all the errors and interpreted everything in sprint-2
1 parent a5a7a2e commit 22f84a7

12 files changed

Lines changed: 50 additions & 26 deletions

File tree

‎Sprint-2/1-key-exercises/1-count.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ count = count + 1;
44

55
// Line 1 is a variable declaration, creating the count variable with an initial value of 0
66
// Describe what line 3 is doing, in particular focus on what = is doing
7+
// line 3 is adding 1 to the count variable
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
const firstName = "Creola";
22
const middleName = "Katherine";
33
const lastName = "Johnson";
4+
let initials=firstName.charAt(0)+middleName.charAt(0)+lastName.charAt(0)
45

56
// Declare a variable called initials that stores the first character of each string.
67
// This should produce the string "CKJ", but you must not write the characters C, K, or J in the code of your solution.
78

8-
const initials = ``;
9-
9+
//initials = ``;
10+
console.log(initials)
1011
// https://www.google.com/search?q=get+first+character+of+string+mdn

‎Sprint-2/1-key-exercises/3-paths.js‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ console.log(`The base part of ${filePath} is ${base}`);
1717
// Create a variable to store the dir part of the filePath variable
1818
// Create a variable to store the ext part of the variable
1919

20-
const dir = ;
21-
const ext = ;
22-
20+
const dir =filePath.slice(13,16) ;
21+
const ext =filePath.slice(50,53);
22+
console.log(`the directory of the file path is: ${dir}`)
23+
console.log(`the extension of the file path is: ${ext}`)
2324
// https://www.google.com/search?q=slice+mdn

‎Sprint-2/1-key-exercises/4-random.js‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ const maximum = 100;
44
const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
55

66
// In this exercise, you will need to work out what num represents?
7+
78
// Try breaking down the expression and using documentation to explain what it means
9+
//math.floor rounds down the whole number
10+
//math.random generates a random number between 0 and 1
11+
//max - min +1 =98
12+
//add 1
813
// It will help to think about the order in which expressions are evaluated
914
// Try logging the value of num and running the program several times to build an idea of what the program is doing
15+
console.log(num)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
This is just an instruction for the first activity - but it is just for human consumption
2-
We don't want the computer to run these 2 lines - how can we solve this problem?
1+
//This is just an instruction for the first activity - but it is just for human consumption
2+
//We don't want the computer to run these 2 lines - how can we solve this problem?

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// trying to create an age variable and then reassign the value by 1
22

3-
const age = 33;
3+
let age = 33;
44
age = age + 1;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Currently trying to print the string "I was born in Bolton" but it isn't working...
22
// what's the error ?
3-
4-
console.log(`I was born in ${cityOfBirth}`);
53
const cityOfBirth = "Bolton";
4+
console.log(`I was born in ${cityOfBirth}`);
5+

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
const cardNumber = 4533787178994213;
2-
const last4Digits = cardNumber.slice(-4);
2+
const last4Digits = cardNumber.toString().slice(-4);
3+
4+
//maybe the error isn't running because of the function used to get the last 4 digits
5+
36

47
// The last4Digits variable should store the last 4 digits of cardNumber
58
// However, the code isn't working
69
// Before running the code, make and explain a prediction about why the code won't work
710
// Then run the code and see what error it gives.
811
// Consider: Why does it give this error? Is this what I predicted? If not, what's different?
12+
//it says .slice() is not a fnction, i was right
913
// Then try updating the expression last4Digits is assigned to, in order to get the correct value
14+
console.log(last4Digits)

‎Sprint-2/2-mandatory-errors/4.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
const 12HourClockTime = "8:53pm";
2-
const 24hourClockTime = "20:53";
1+
const Hour12ClockTime = "8:53pm";
2+
const hour24ClockTime = "20:53";
3+
4+
//cant start variable name with number or special char

‎Sprint-2/3-mandatory-interpret/1-percentage-change.js‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,22 @@ let carPrice = "10,000";
22
let priceAfterOneYear = "8,543";
33

44
carPrice = Number(carPrice.replaceAll(",", ""));
5-
priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
5+
priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
66

7-
const priceDifference = carPrice - priceAfterOneYear;
8-
const percentageChange = (priceDifference / carPrice) * 100;
7+
const priceDifference = carPrice.toInt() - priceAfterOneYear.toInt();
8+
const percentageChange = (priceDifference.toInt() / carPrice.toInt()) * 100;
99

1010
console.log(`The percentage change is ${percentageChange}`);
1111

1212
// Read the code and then answer the questions below
1313

1414
// a) How many function calls are there in this file? Write down all the lines where a function call is made
15-
15+
//2
1616
// b) Run the code and identify the line where the error is coming from - why is this error occurring? How can you fix this problem?
17-
17+
//maybe the function is doing mathematical operations to string, there wasnt a comma for the second replace function
1818
// c) Identify all the lines that are variable reassignment statements
19-
19+
//4
2020
// d) Identify all the lines that are variable declarations
21-
21+
//2
2222
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
23+
//it is removing all the commas and replacing it with an empty space, to make calculations easier

0 commit comments

Comments
 (0)