Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
d20c0a3
describing what line 3 is doing (reassignment)
djebsoft Feb 23, 2026
3428f41
producing the string "CKJ"
djebsoft Feb 24, 2026
38427c2
creating variable to store specific part (slice) of string
djebsoft Feb 25, 2026
2f3f08d
building an idea of what a program is doing
djebsoft Feb 25, 2026
44271ba
Convert instructions to comments
djebsoft Feb 25, 2026
e0b3256
Use 'let' for age variable to enable reassignment
djebsoft Feb 25, 2026
21914bb
Correct variable declaration for cityOfBirth
djebsoft Feb 25, 2026
17d93a6
Fix the typeOf variable to be able to use a method
djebsoft Feb 25, 2026
af48176
Rename clock time variables to valid identifiers
djebsoft Feb 25, 2026
4ba270e
Fix syntax error in priceAfterOneYear assignment
djebsoft Feb 26, 2026
67c8968
generating time format for duration of a movie
djebsoft Feb 26, 2026
b72751f
describing the purpose behind each step of the code
djebsoft Feb 27, 2026
35fdc82
Fix variable redeclaration in a function
djebsoft Feb 27, 2026
4fdfb07
declaraing the variable 'result' in capitalise function
djebsoft Feb 27, 2026
d100737
Fix duplicate variable declaration and assigning in convertToPercenta…
djebsoft Feb 27, 2026
3bcd5ba
Fix square function parameter
djebsoft Feb 27, 2026
5809aee
Fix multiply function to return result and log output
djebsoft Feb 27, 2026
eee4034
Correct sum function to return the sum of arguments
djebsoft Feb 27, 2026
db44748
Fix getLastDigit function to return correct last digit
djebsoft Feb 28, 2026
429f649
Implement upperSnakeCase function
djebsoft Mar 1, 2026
92bd8ef
Implement toPounds function
djebsoft Mar 1, 2026
56b74d5
Clarify pad function behavior in comments
djebsoft Mar 1, 2026
5196c63
Clean up comments in time-format.js
djebsoft Mar 1, 2026
122c731
Refactor toPounds function
djebsoft Mar 1, 2026
7d09f40
Remove upperSnakeCase function restore the file to the main version
djebsoft Mar 1, 2026
7b87fbc
Update 2.js
djebsoft Mar 1, 2026
652dbc1
Update 1.js
djebsoft Mar 1, 2026
bbdcc95
Update 2.js
djebsoft Mar 1, 2026
177c368
Update 1.js
djebsoft Mar 1, 2026
3bb9ddf
Update 0.js
djebsoft Mar 1, 2026
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
2 changes: 1 addition & 1 deletion Sprint-1/1-key-exercises/1-count.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ let count = 0;
count = count + 1;

// 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
// the third line used the the assignment operator '=' to reassign the variable count to the initial value which is zero incremented by one resulting to the value 1
6 changes: 5 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,11 @@ 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);
// or
let initials = firstName[0] + middleName[0] + lastName[0];
// or but rarely used and not recommended because it might cause bugs
let initials = firstName[0].concat(middleName[0], lastName[0]);

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

9 changes: 6 additions & 3 deletions Sprint-1/1-key-exercises/3-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ 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 dir = filePath.slice(0,lastSlashIndex+1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you intend to include a trailing / in the value assigned to dir?

const ext = filePath.slice(-3); //the extention of the file is always the last three characters in the path
//or
const lastPointIndex = filePath.lastIndexOf(".");
const ext = filePath.slice(lastPointIndex+1);
Comment on lines +23 to +24
Copy link
Contributor

Choose a reason for hiding this comment

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

This approach is better because it works for extensions of any length.


// https://www.google.com/search?q=slice+mdn
// https://www.google.com/search?q=slice+mdn
11 changes: 11 additions & 0 deletions Sprint-1/1-key-exercises/4-random.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,14 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
// 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

// the num represents a value with limited interval and that's why
// the num assigned to a value that's in the dor of an expression
// the math object is invoked to perform some mathematical tasks
// the random method is invoked to get a random number between 0 and 1
// the random number is multiplied by 100
// the floor method is invoked to round down the result to its nearest integer
// added one to the new result
// the final result of the whole expression is what the variable num assigned to
/* after applying the program several times, I got the idea that the program is generating
a value to the num variable thats always between minimum an maximum*/
Comment on lines +11 to +20
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.

5 changes: 3 additions & 2 deletions Sprint-1/2-mandatory-errors/0.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
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?
// to make the computer not running these two line we use inline comments by adding two slashes at the beginning of each line
2 changes: 1 addition & 1 deletion Sprint-1/2-mandatory-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// trying to create an age variable and then reassign the value by 1

const age = 33;
let age = 33; // we should use the keyword 'let' to declare the variable 'age' to allow reassignment later
age = age + 1;
4 changes: 3 additions & 1 deletion Sprint-1/2-mandatory-errors/2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Currently trying to print the string "I was born in Bolton" but it isn't working...
// what's the error ?

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

// the error is that the variable 'cityOfBirth' is declared after the statement it is used in
11 changes: 10 additions & 1 deletion Sprint-1/2-mandatory-errors/3.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
const cardNumber = 4533787178994213;
const last4Digits = cardNumber.slice(-4);
const last4Digits = (cardNumber.toString()).slice(-4);
Copy link
Contributor

Choose a reason for hiding this comment

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

Dot operator is evaluated from left to right. So the parentheses around cardNumber.toString() is optional, and is usually omitted.


// The last4Digits variable should store the last 4 digits of cardNumber
// However, the code isn't working
// Before running the code, make and explain a prediction about why the code won't work
// Then run the code and see what error it gives.
// Consider: Why does it give this error? Is this what I predicted? If not, what's different?
// Then try updating the expression last4Digits is assigned to, in order to get the correct value

/* my prediction about why the code isn't working is because either the new variable is declared with const keyword
or the value of the variable cardNumber is a number not a string whereas the method .slice works only with strings */
// the error it gives 'cardNumber.slice is not a function'
// It gives this error because the computer assumes the coder is trying to invoke a function
// yes it is my second prediction
// updating the expression last4Digits is assigned to, in order to get the correct value is as follows
// method one: puting the value of the variable cardNumber into quotes
// method two: invoking the method .toString() to convert the type of the variable from number to string
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 _12HourClockTime = "20:53"; // identifier can not begin with a number
// or
const $12HourClockTime = "20:53"; // or any change that makes the identifier not stating with digit
const _24hourClockTime = "08:53"; // identifier can not begin with a number
// or
const $24hourClockTime = "08:53"; // or any change that makes the identifier not stating with digit
Copy link
Contributor

Choose a reason for hiding this comment

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

Starting a variable name with a $ is generally not recommended.

Normal practice is to begin a variable name with a lowercase letter.

15 changes: 14 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(",", ""));

const priceDifference = carPrice - priceAfterOneYear;
const percentageChange = (priceDifference / carPrice) * 100;
Expand All @@ -12,11 +12,24 @@ console.log(`The percentage change is ${percentageChange}`);
// Read the code and then answer the questions below

// a) How many function calls are there in this file? Write down all the lines where a function call is made
// there are five function calls in this file, the lines where a call function is made are as follows:
// line 4, replaceAll()
// line 4, Number()
// line 5, replaceAll()
// line 5, Number()
// line 10, console.log()

// 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?
// the error is coming from line 5
// it is a syntax error, the expression priceAfterOneYear.replaceAll("," "") ismissing a comma
// to fix this problem we add comma between the two arguments

// c) Identify all the lines that are variable reassignment statements
// the lines that are variable reassignment statements: -line 4 -line 5

// d) Identify all the lines that are variable declarations
// the lines that are variable declarations: -line 1 -line 2 -line 7 -line 8

// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
// the expression calls the replace method to replace the comma with empty string
// converting the new string to a number to be able to perform math operations
7 changes: 7 additions & 0 deletions Sprint-1/3-mandatory-interpret/2-time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,21 @@ console.log(result);
// For the piece of code above, read the code and then answer the following questions

// a) How many variable declarations are there in this program?
// there are 6 variable declaration

// b) How many function calls are there?
// there is one function call (console.log())

// c) Using documentation, explain what the expression movieLength % 60 represents
// it represents the remaining of dividing movielength by 60
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators

// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
// it means the integer quotient of dividing movieLength by 60

// e) What do you think the variable result represents? Can you think of a better name for this variable?
// it represents the length of the movie in hours, minutes and seconds format
// a better name would be: movieTimeVolume
Copy link
Contributor

Choose a reason for hiding this comment

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

The name movieTimeVolume does not quite indicate the value stored in the variable
is a formatted string in the form "2:12:02".

Can you suggest a more descriptive name?


// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
// no it will not work for negative input values as it gives negative results
5 changes: 5 additions & 0 deletions Sprint-1/3-mandatory-interpret/3-to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,8 @@ console.log(`£${pounds}.${pence}`);

// To begin, we can start with
// 1. const penceString = "399p": initialises a string variable with the value "399p"
// line 3: calling substring method to remove the 'p' letter and keep only digits in the string
// line 8: using padstart method to make the minimum length of the string to 3 characters by adding one zero or two to the left.
// line 9: using substring method to take only the integer part
// line 14: using substring method to take only the decimal part and padend method to make the minimum length of pence to 2 characters by adding zero to the right
Copy link
Contributor

Choose a reason for hiding this comment

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

Optional challenge:
Could we expect this program to work as intended for any valid penceString if we deleted .padEnd(2, "0") from the code?
In other words, do we really need .padEnd(2, "0") in this script?

// line 18: calling console function to print the integer part that represents the pound and the decimal part that represents the pence seprated by point
2 changes: 0 additions & 2 deletions Sprint-2/1-key-errors/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,3 @@ function square(3) {
// Finally, correct the code to fix the problem

// =============> write your new code here


18 changes: 15 additions & 3 deletions Sprint-2/2-mandatory-debug/0.js
Copy link
Contributor

Choose a reason for hiding this comment

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

There should not be modified files in the Sprint-2 folder in a PR created for Sprint-1 exercise.

Can you revert (undo) the changes made in the Sprint-2 folder?

Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
// Predict and explain first...

// =============> write your prediction here
// =============> the function when called will throw an error

function multiply(a, b) {
console.log(a * b);
}

console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);

// =============> write your explanation here
// =============> the function multiply has no return statement

// Finally, correct the code to fix the problem
// =============> write your new code here
// =============>
function multiply(a, b) {
return (a * b); // we change the console.log statement with the return statement
}

console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);

// an extra notice: the purpose of creating a function is to reuse it when needed
// I've noticed that the parameters are already assigned to values 10 and 32, so I changed the code to the following:
function multiply(a, b) {
return console.log(`The result of multiplying ` + a +` and ` + b +` is ` + (a * b));
}
multiply(10, 32);
2 changes: 1 addition & 1 deletion Sprint-2/4-mandatory-interpret/time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function formatTimeDisplay(seconds) {
// Questions

// a) When formatTimeDisplay is called how many times will pad be called?
// =============> write your answer here


// Call formatTimeDisplay with an input of 61, now answer the following:

Expand Down
Loading