Skip to content

Commit 3f5aecf

Browse files
committed
sprint 1 course work
1 parent ebed26d commit 3f5aecf

14 files changed

Lines changed: 101 additions & 29 deletions

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@ 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+
8+
9+
// Line 3 takes the initial value of count and adds 1 to it
10+
// the = "count + 1 rewrites the count variable to the newly calculated value"

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.charAt(0)}${middleName.charAt(0)}${lastName.charAt(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: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,18 @@
1212
const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt";
1313
const lastSlashIndex = filePath.lastIndexOf("/");
1414
const base = filePath.slice(lastSlashIndex + 1);
15-
console.log(`The base part of ${filePath} is ${base}`);
1615

1716
// Create a variable to store the dir part of the filePath variable
1817
// Create a variable to store the ext part of the variable
1918

20-
const dir = ;
21-
const ext = ;
19+
const firstSlashIndex = filePath.indexOf("/");
20+
const dir = filePath.slice(firstSlashIndex + 1, lastSlashIndex - 1);
2221

23-
// https://www.google.com/search?q=slice+mdn
22+
const lastdotindex = filePath.lastIndexOf(".");
23+
const ext = filePath.slice(lastdotindex);
24+
25+
console.log(`The base part of ${filePath} is ${base}
26+
The dir is ${dir}
27+
and the ext is ${ext}`);
28+
29+
// https://www.google.com/search?q=slice+mdn
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
const minimum = 1;
2-
const maximum = 100;
1+
const minimum = 80;
2+
const maximum = 83;
33

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?
77
// Try breaking down the expression and using documentation to explain what it means
88
// It will help to think about the order in which expressions are evaluated
99
// Try logging the value of num and running the program several times to build an idea of what the program is doing
10+
console.log(num);

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
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+
4+
comment them out!*/

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

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

3-
const age = 33;
4-
age = age + 1;
3+
let age = 33;
4+
age = age + 1;
5+
console.log(age);
6+
7+
// it needed to be a variabal not a constant
8+
9+

Sprint-1/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+
// the constant was declared after the sentence that used it

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
const cardNumber = 4533787178994213;
1+
const cardNumber = "4533787178994213";
22
const last4Digits = cardNumber.slice(-4);
3-
3+
console.log(last4Digits);
44
// The last4Digits variable should store the last 4 digits of cardNumber
55
// However, the code isn't working
66
// Before running the code, make and explain a prediction about why the code won't work
77
// Then run the code and see what error it gives.
88
// Consider: Why does it give this error? Is this what I predicted? If not, what's different?
99
// Then try updating the expression last4Digits is assigned to, in order to get the correct value
10+
11+
12+
//it will not work because the cardNumber is a number and not a string so it cant use the slice method

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,17 @@
1-
const 12HourClockTime = "20:53";
2-
const 24hourClockTime = "08:53";
1+
//const twelveHourClockTime = "20:53";
2+
//const twentyFourHourClockTime = "08:53";
3+
4+
//variable names can't start with a number
5+
6+
// the times are in the wrong places ie:-20:53 is not a twelve hour time and as they are const they cant be directly changed
7+
8+
let twelveHourClockTime = "20:53";
9+
let twelthHour = twelveHourClockTime.substring(0, twelveHourClockTime.length -3);
10+
if (twelthHour >12) {twelthHour = twelthHour - 12};
11+
let twelthMinutes = twelveHourClockTime.substring(2, twelveHourClockTime.length)
12+
13+
let twentyFourHourClockTime = "08:53";
14+
15+
16+
console.log(`${twelthHour}${twelthMinutes}`);
17+
console.log(twentyFourHourClockTime);

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

Lines changed: 10 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;
@@ -13,10 +13,19 @@ console.log(`The percentage change is ${percentageChange}`);
1313

1414
// a) How many function calls are there in this file? Write down all the lines where a function call is made
1515

16+
// carPrice = Number(carPrice.replaceAll(",", ""));
17+
// priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
18+
// both use a call to read the string as a number and to replaceAll the comas with a null value
19+
20+
1621
// 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?
22+
// the error is on line 5 there should be a coma after the "," to make the change
1723

1824
// c) Identify all the lines that are variable reassignment statements
25+
// lines 5 and 6 reassign the variables from the string to a number so that we can do a calculation on it
1926

2027
// d) Identify all the lines that are variable declarations
28+
// lines 1, 2, 7 and 8
2129

2230
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
31+
// it is changing the string "10,000" to a number and removing the comma so it can be used in the calculation

0 commit comments

Comments
 (0)