Skip to content

Commit 08cf329

Browse files
committed
Have completed all the coursework for sprint 1
1 parent 3372770 commit 08cf329

File tree

12 files changed

+50
-19
lines changed

12 files changed

+50
-19
lines changed

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

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

55
// Line 1 is a variable declaration, creating the count variable with an initial value of 0
6-
// Describe what line 3 is doing, in particular focus on what = is doing
6+
// Line 3 is adding 1 to the initial count of 0 which is given in the variable declaration (Describe what line 3 is doing, in particular focus on what = is doing)

Sprint-1/1-key-exercises/2-initials.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ let lastName = "Johnson";
55
// Declare a variable called initials that stores the first character of each string.
66
// This should produce the string "CKJ", but you must not write the characters C, K, or J in the code of your solution.
77

8-
let initials = ``;
8+
let initials = `${firstName[0]}${middleName[0]}${lastName[0]}`;
9+
console.log(initials);
910

1011
// https://www.google.com/search?q=get+first+character+of+string+mdn
1112

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ 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 = ;
20+
const dir = filePath.slice(0,lastSlashIndex);
21+
const lastDotIndex = filePath.lastIndexOf(".");
22+
const ext = filePath.slice(lastDotIndex + 1);
23+
console.log (`The dir part of the filePath variable is ${dir}`);
24+
console.log (`The ext part of the variable is ${ext}`);
2225

2326
// https://www.google.com/search?q=slice+mdn

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ const maximum = 100;
33

44
const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
55

6-
// In this exercise, you will need to work out what num represents?
7-
// Try breaking down the expression and using documentation to explain what it means
6+
// In this exercise, you will need to work out what num represents? Num represents a randomly selected number from >=1 till <=100
7+
// Try breaking down the expression and using documentation to explain what it means.
8+
// Function Math.random() generates a decimal number between 0 to 1 which is 0 to 0.9999
9+
// Funcion (maximum-minimum + 1). Therefore it is 100 - 1 + 1 = 100
10+
// The * sign will multiply the random number with 100 which becomes 0 to 99.99
11+
// The function Math.floor will round the new number to the nearest whole number. Hence it will be 0 to 99
12+
// + minimum will add 1 to the new rounded up number Hence the old rance 0 - 99 will now become 1 to 100
813
// It will help to think about the order in which expressions are evaluated
9-
// Try logging the value of num and running the program several times to build an idea of what the program is doing
14+
// Done - Try logging the value of num and running the program several times to build an idea of what the program is doing

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
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?
3+
// we add the double slash which treats it like a comment for human consumption

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
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;
5+
console.log (age)

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Currently trying to print the string "I was born in Bolton" but it isn't working...
2-
// what's the error ?
2+
// what's the error ? We cannot declare after execution. We need to declare first
33

4-
console.log(`I was born in ${cityOfBirth}`);
54
const cityOfBirth = "Bolton";
5+
console.log(`I was born in ${cityOfBirth}`);
6+

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
const cardNumber = 4533787178994213;
1+
const cardNumber = "4533787178994213";
22
const last4Digits = cardNumber.slice(-4);
33

4+
console.log(last4Digits);
5+
46
// The last4Digits variable should store the last 4 digits of cardNumber
57
// However, the code isn't working
8+
// since it was not in quotes
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?

Sprint-1/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 = "20:53";
2-
const 24hourClockTime = "08:53";
1+
const Clock12HourTime = "20:53";
2+
const Clock24HourTime = "08:53";
3+
4+
// The varialble cannot start with a number of function

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ 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

77
const priceDifference = carPrice - priceAfterOneYear;
88
const percentageChange = (priceDifference / carPrice) * 100;
@@ -12,11 +12,16 @@ console.log(`The percentage change is ${percentageChange}`);
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+
// There are 3 function calls on line 4,5 & 10
1516

1617
// 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?
18+
// The error is on line 5. It is missing a , syntax. I have fixed it
1719

1820
// c) Identify all the lines that are variable reassignment statements
21+
// Lines 4 & 5 are variable reassignment statements
1922

2023
// d) Identify all the lines that are variable declarations
24+
// Variable declarations are lines 1,2,7 & 8
2125

2226
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
27+
// This expression is removing the , between the car price and making it into a number without ,

0 commit comments

Comments
 (0)