Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Sprint-1/1-key-exercises/1-count.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
let count = 0;

count = count + 1;
/* in line three, the variable count is reassign new value by increment it current value by 1.
*/
console.log(count);

// Line 1 is a variable declaration, creating the count variable with an initial value of 0
// Describe what line 3 is doing, in particular focus on what = is doing
3 changes: 2 additions & 1 deletion Sprint-1/1-key-exercises/2-initials.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ let lastName = "Johnson";
// Declare a variable called initials that stores the first character of each string.
// This should produce the string "CKJ", but you must not write the characters C, K, or J in the code of your solution.

let initials = ``;
let initials = firstName.charAt(0)+middleName.charAt(0)+lastName.charAt(0);
console.log(initials);

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

15 changes: 12 additions & 3 deletions Sprint-1/1-key-exercises/3-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,17 @@ console.log(`The base part of ${filePath} is ${base}`);

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

const dir = ;
const ext = ;
/*
const slashIndex = filePath.indexOf("/");
const dir =filePath.slice(slashIndex + 0, 45) ;
const ext =filePath.slice(slashIndex + 49, 53);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why keep this code? Best practice is to remove unused code to keep our code clean. And doing so also helps make code review easier.

console.log(`The dir part of ${filePath} is ${dir}`);
console.log(`The ext part of ${filePath} is ${ext}`);
*/

let dirDirectory = filePath.slice(filePath.indexOf("/"),filePath.lastIndexOf("/"));
let extDirectory = filePath.slice(filePath.lastIndexOf("/"));
console.log(`The dir part of the file is ${dirDirectory}.`);
console.log(`The ext part of the file is ${extDirectory}.`);
Comment on lines +27 to +30
Copy link
Contributor

@cjyuan cjyuan Mar 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suppose filePath is "/tmp/file.txt". Based on your understanding of the anatomy of a file path on lines 3-8, can you tell which part of the file path is considered the dir part and which part of it is considered the ext part?

When you run your code, does your code output the values you expected?


// https://www.google.com/search?q=slice+mdn
9 changes: 9 additions & 0 deletions Sprint-1/1-key-exercises/4-random.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@ const maximum = 100;

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

console.log(num)

// In this exercise, you will need to work out what num represents?
// Try breaking down the expression and using documentation to explain what it means
// It will help to think about the order in which expressions are evaluated
// Try logging the value of num and running the program several times to build an idea of what the program is doing

/*Number data type represents any type of number such as integer, float number(decimal number), infinity number, etc...
In the code at line 4 the num variable are doing math function that generate a integer between variable minimum and maximum value,
the floor method behind the Math are is main purpose if to help turn value of a float number and round it up to the nearest integer.
inside the Math.floor parameter the math random method is choosing a random float number between 0 and 1 and have it multiply with the second expression
to set the range of possible value range from 0 to under 100. The last plus one to make sure the that number stay above 0(0+1) and to 100(99+1);
*/
Comment on lines +12 to +18
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Phrases like "a number between X and Y" are not precise enough in a program specification, because they do not clearly state whether the endpoints X and Y are included.

We can also use the concise and precise interval notation to describe a range of values.

  • [, ] => inclusion
  • (, ) => exclusion

For example, [1, 10) means, all numbers between 1 and 10, including 1 but excluding 10.


Can you practice this and use it to describe the range of numbers that could be produced in each of these sub-expressions?

  1. Math.random()
  2. Math.random() * (maximum - minimum + 1)
  3. Math.floor(Math.random() * (maximum - minimum + 1))
  4. Math.floor(Math.random() * (maximum - minimum + 1)) + minimum

6 changes: 4 additions & 2 deletions Sprint-1/2-mandatory-errors/0.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
This is just an instruction for the first activity - but it is just for human consumption
We don't want the computer to run these 2 lines - how can we solve this problem?
/*This is just an instruction for the first activity - but it is just for human consumption
We don't want the computer to run these 2 lines - how can we solve this problem?
By comment both the line 1 and 2 out and the system should ignore these 2 line and see them as comment.
*/
8 changes: 6 additions & 2 deletions Sprint-1/2-mandatory-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
// trying to create an age variable and then reassign the value by 1

const age = 33;
age = age + 1;
let age = 33;
age += 1 ;

console.log(age);

/*By changing the variable from const to let since const variable value can't be change. I used prefix to increase the value and reassign it right away.*/
4 changes: 4 additions & 0 deletions Sprint-1/2-mandatory-errors/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@

console.log(`I was born in ${cityOfBirth}`);
const cityOfBirth = "Bolton";

/*the main the error here is that the console.log try to print the expression string template with the variable cityOfBirth. But since in the variable
cityOfBirth declare after the console.log, so the console.log when try to involve the cityOfBirth will return error since the it doesn't exist.
*/
4 changes: 3 additions & 1 deletion Sprint-1/2-mandatory-errors/3.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const cardNumber = 4533787178994213;
const last4Digits = cardNumber.slice(-4);
const last4Digits = cardNumber.toString().slice(-4);
console.log(last4Digits);
console.log(typeof last4Digits);

// The last4Digits variable should store the last 4 digits of cardNumber
// However, the code isn't working
Expand Down
8 changes: 6 additions & 2 deletions Sprint-1/2-mandatory-errors/4.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
const 12HourClockTime = "20:53";
const 24hourClockTime = "08:53";
const twelveHourClockTime = "20:53";
const twentyFourHourClockTime = "08:53";
console.log($12HourClockTime);
console.log($24HourClockTime);

Comment on lines +1 to +5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You changed only part of the code. As such, the code won't run.

/*For this error I I fix by changing the number 12 and 24 to word variable name because in JS number can't be used to begin writing a variable name */
29 changes: 28 additions & 1 deletion Sprint-1/3-mandatory-interpret/1-percentage-change.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ let carPrice = "10,000";
let priceAfterOneYear = "8,543";

carPrice = Number(carPrice.replaceAll(",", ""));
priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
Copy link

@ykamal ykamal Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine, but the link below is worth looking into. it's an abstraction over this and will probably serve you better in the long run:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ykamal Thank you for the link. I have read through and see that it indeed more organise then the current method I write in the code. I will try to used in my course work next time.


const priceDifference = carPrice - priceAfterOneYear;
const percentageChange = (priceDifference / carPrice) * 100;
Expand All @@ -20,3 +20,30 @@ console.log(`The percentage change is ${percentageChange}`);
// d) Identify all the lines that are variable declarations

// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?

/*
Answer
a) In this section of the code, we have function calls appear 5 time through out the code. Here is each of them on the line of code that
they are call:
- Number(carPrice.replaceAll(",","")); in line 4 is a function calls because the .replaceALL is being executed
- Number(priceAfterOneYear.replaceAll(",", "")); in line 5 is also a function call because .replaceAll is being executed.
- Inside the Number() function the .replaceAll in both line 4 and 5 is also a function call because the the parent function is also
being executed.
- the console.log is a function calls
So the total amount of function call in this code is 5

b) The main error for the when the running this line of code if for the missing right parameter between the arguments, so fix this
just add the coma right after the double quote.

c) There are 2 reassign variable statement at line 4 and line 5.

d)There are 4 total variable declarations in this code:
- let carPrice = "10,00"; line 1
- let priceAfterOneYear ="8,543"; line 2
- const priceDifference = carPrice - priceAfterOneYear; line 7
- const percentageChange = (priceDifference / carPrice) * 100; line 8

e) The expression Number(carPrice.replaceAll(",","")) are doing 2 main purpose,
- The first purpose is to remove the coma from the string number "10000" and "8543".
- Is the changing the string number to number data type.
*/
28 changes: 28 additions & 0 deletions Sprint-1/3-mandatory-interpret/2-time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,31 @@ console.log(result);
// e) What do you think the variable result represents? Can you think of a better name for this variable?

// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer

/*
Answer
a)In this program there are 5 variable declarations:
-const movieLength = 8784; at line 1.
-const remainingSeconds = movieLength % 60; at line 3.
-const totalMinutes = (movieLength - remainingSeconds) / 60; at line 4.
-const remainingMinutes = totalMinutes % 60; at line 6.
-const totalHours = (totalMinutes - remainingMinutes) / 60; at line 7.

b) There are only 1 function call in this program.
- console.log(result); at line 10

c)At the line 3 we can see the the expression movieLength % 60,
what is represent is the reminder value after the division movieLength(in second) value by 60%;
this is to remind how much left over second left in the movie.

d)In line 4, the the expression that is assigned to totalMinutes
represent the value after the math operation if movieLength value and remainingSeconds then divine by 60;

e)For the variable result it represent the combine total time length of the movie in hour/minutes/second template, for better name for this variable
I would to rename it to formattedMovieDuration.

f) After the experimenting with different values of movieLength. As Long as the value in movieLength is a positive integer of second. It will
correctly produce the correct value in hours/minutes/second format. However for to the other value such as float number, string, negative integer
and non numeric value. They might still print out in the format hours/minutes/second but some type will break code such as if string not a number or coma in a string
number, negative value that don't reflect what this code try to do or decimal number that give incorrect result.
*/
29 changes: 28 additions & 1 deletion Sprint-1/3-mandatory-interpret/3-to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,31 @@ console.log(`£${pounds}.${pence}`);
// Try and describe the purpose / rationale behind each step

// To begin, we can start with
// 1. const penceString = "399p": initialises a string variable with the value "399p"
/*
1. const penceString = "399p": initializes a string variable with the value "399p".

2. const penceStringWithoutTrailingP: this variable is now store a new value of penceString "399".
By using the .substring method(.slice method predecessor)it remove the p from the penceString value and
reassign the new value to variable penceStringWithoutTrailingP. It start from index position 0 in this case "3" and stop at the index 2 "9".

3. const paddedPenceNumberString: this variable main role is to check if the string value total length
at least 3, if the length short then padStart will add 0 the left from the first index(0) in this case "3" until the string length total is 3. In this case
it select the string number "3".

4. const pounds: this variable is role is to extract the pound value from the paddedPenceNumberString.
Inside the the paddedPenceNumberString subString method parameter it have 2 value 0 and paddedPenceNumberString total string length minus 1,
the 0 is the index of the string number that we would like to start while .length - 2 is to tell the SubString method where to stop in this case the first "9".

5) const pence: as the name suggest this variable main role is to extract he pence value from the paddedPenceNumberString variable.
How ever this variable there are 2 method is used.
-subString method is used to slice the string value "99" off the "399" value, how ever is now only have 1 value
is the length of the "399" is 3 now - 2 equal to 1 and no end value. The main reason is to select where the slice will begin stop at the end
of the string.
-padEnd method work exactly the same as padStart but in reverse. The padEnd method is checking to see is the paddedPenceNumberString string length at least total of 2,
if not they will add 0 from the selected index position from the string value "99" from the index 0 in this case is "9" to the right.

6)console.log(`£${pounds}.${pence}`): is to log and print out the value inside the terminal by using the string template, the back tick is to
define a template literal. Then inside the template the pound sign(£) is show the pound currency, the money sign before the curly bracket is to allow
embed variables in this case pounds and pence that separate by dot that print out a float string value.
*/

Loading