Skip to content

Commit 522d1bd

Browse files
committed
Completion of Sprint 1 Coursework
1 parent 3372770 commit 522d1bd

File tree

13 files changed

+82
-17
lines changed

13 files changed

+82
-17
lines changed

Sprint-1/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 initial values of count which is 0 and reassing the new value (1+0 =1) to count

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ let lastName = "Johnson";
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

88
let initials = ``;
9+
initials = firstName.substring(0, 1) + middleName.substring(0, 1) + lastName.substring(0, 1)
10+
console.log(initials)
911

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

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.substring(0, 44);
21+
console.log(`The dir part of the filePath variable is ${dir}`);
2222

23+
const lastDotIndex = filePath.lastIndexOf(".");
24+
const ext = filePath.slice(lastDotIndex + 1);
25+
console.log(`The ext of ${filePath} is ${ext}`);
2326
// https://www.google.com/search?q=slice+mdn

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
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+
//ANSWER:
5+
//We change the two lines to comments by using double forward slash (//) at the beginning of the two lines.

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,10 @@
22

33
const age = 33;
44
age = age + 1;
5+
6+
// ANSWER
7+
// In the solution above, 'age' is a constant variable becuse the keyword 'const' was used with it hence the value cannot change.
8+
9+
// Solution:
10+
let age = 33;
11+
let age = age + 1;

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,11 @@
33

44
console.log(`I was born in ${cityOfBirth}`);
55
const cityOfBirth = "Bolton";
6+
7+
//ANSWER:
8+
// The 'cityOfBirth' was not assigned before the console.log statement
9+
// Solution will be to switch the lines as shown below:
10+
11+
12+
const cityOfBirth = "Bolton";
13+
console.log(`I was born in ${cityOfBirth}`);

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,11 @@ const last4Digits = cardNumber.slice(-4);
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+
//Predcition: slice() probably only work on string. Possible solution will be to put cardNumber in quotes or use String()
12+
// Why does it give this error? It says 'cardNumber.slice is not a function'
13+
// Is this what I predicted? No
14+
// If not, what's different? Since cardNumber is numeric, it shoulf be changed to string fot slice() to work.
15+
16+
const cardNumber = "4533787178994213";
17+
const last4Digits = cardNumber.slice(-4);

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,11 @@
11
const 12HourClockTime = "20:53";
2-
const 24hourClockTime = "08:53";
2+
const 24hourClockTime = "08:53";
3+
4+
//In naming variable, numbers are not allowed to preceed variable names.
5+
6+
// Error message: An identifier or keyword cannot immediately follow a numeric literal.
7+
8+
// SUggested Solutions:
9+
10+
const ClockTime12Hour = "20:53";
11+
const ClockTime24hour = "08:53";

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ 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-
15+
//ANSWER: Four function calls. Two function calls in line 4 & two function calls in line 5
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+
//ANSWER: The comma in the replaceAll() function in Line 5 is missing. Put the comma back in to fix it.
1818
// c) Identify all the lines that are variable reassignment statements
19-
19+
//ANSWER: Lines that are variable reassignment statements are Lines 4 & 5.
2020
// d) Identify all the lines that are variable declarations
21-
21+
//ANSWER: Variable declarations line: 1,2,7,& 8
2222
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
23+
//ANSWER: The expression first removes the comma(,) in carPrice and then converts it to a number.

Sprint-1/3-mandatory-interpret/2-time-format.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ console.log(result);
1212
// For the piece of code above, read the code and then answer the following questions
1313

1414
// a) How many variable declarations are there in this program?
15-
15+
//ANSWER: There were six variable declarations
1616
// b) How many function calls are there?
17-
17+
//ANSWER: There were no function calls except for the log() function
1818
// c) Using documentation, explain what the expression movieLength % 60 represents
1919
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
20-
20+
//ANSWER: The remainder (%) operator returns the remainder left over when one operand is divided by a second operand. It always takes the sign of the dividend.
2121
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
22-
22+
//ANSWER: Line 4 with find the remainder whenmovieLength is divided by 60 and assigns the remainder to remainingSeconds (24)
2323
// e) What do you think the variable result represents? Can you think of a better name for this variable?
24-
24+
//ANSWER: The variable result represents the total lenth of the movie which shows the total hours, minutes and seconds remain in string format.
2525
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
26+
//ANSWER: The code semed to work for all values of movieLength.

0 commit comments

Comments
 (0)