Skip to content
Open
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
e1447e3
Increase by 1 the variable count
carlosyabreu Nov 3, 2025
f184b29
Assignment operator equal
carlosyabreu Nov 6, 2025
d88693e
2-initials.js first letters of the variables
carlosyabreu Nov 6, 2025
ad07e16
Directory and extension part of a file path
carlosyabreu Nov 6, 2025
fc159be
Explanation of 4-random.js file
carlosyabreu Nov 6, 2025
92d1f33
Using comment to explain the information contain in the file, useful …
carlosyabreu Nov 6, 2025
204a98d
Change keyword 'const' to 'let' to assign variable
carlosyabreu Nov 6, 2025
b9538b2
Variable must be declared first before it can be used
carlosyabreu Nov 6, 2025
5b6a38f
Extracting the last 4 digits and display it
carlosyabreu Nov 7, 2025
57e97e9
Change variable naming starting with letter instead of numbers
carlosyabreu Nov 7, 2025
7e75245
Change function replaceAll arguments adding commas to separate its pa…
carlosyabreu Nov 7, 2025
a36e485
commit 2-time-format.js and 3-to-pounds.js
carlosyabreu Nov 7, 2025
94b7128
Add alert and prompt function explanation
carlosyabreu Nov 7, 2025
269ce23
Console.log and Console and property
carlosyabreu Nov 7, 2025
7069bdc
Change 1-count.js file
carlosyabreu Nov 10, 2025
f5e4d38
Change 4-random.js file
carlosyabreu Nov 10, 2025
9710e5f
Made change to the file
carlosyabreu Nov 10, 2025
ce03285
Use the short circut increment instead the traditonal one
carlosyabreu Nov 10, 2025
cedc8a3
Comment about variable hoisting
carlosyabreu Nov 10, 2025
dc0e00d
Converting a number to use slice function and display the last 4 digits
carlosyabreu Nov 10, 2025
5726e67
Stay the same as before
carlosyabreu Nov 10, 2025
044b702
Adjust the output adding the percentage symbol
carlosyabreu Nov 10, 2025
bec2478
Redesign the explanation
carlosyabreu Nov 11, 2025
3adb077
Changed the comments and implementation making it more cleaner and sh…
carlosyabreu Nov 11, 2025
2128a93
Explaining alert() and prompt() functions
carlosyabreu Nov 11, 2025
85de39e
Explain the meaning of console.log and various console property and m…
carlosyabreu Nov 11, 2025
0bbf7d8
Remote commented code making the branch clean
carlosyabreu Nov 13, 2025
f845550
Delete package-lock.json
carlosyabreu Nov 14, 2025
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
4 changes: 0 additions & 4 deletions .gitignore

This file was deleted.

8 changes: 8 additions & 0 deletions Sprint-1/1-key-exercises/1-count.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,11 @@ 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

/**
* Line 3: the variable count in right end side increment by 1 and assign the result to left end side which hold the
* incremention
*/

console.log('Value of count variable after incremented by 1: ', count)

4 changes: 3 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,9 @@ 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 = ``;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please remove this commented code to keep the PR clean?

Copy link
Author

Choose a reason for hiding this comment

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

Evening Jenny

Thanks for your reply.
I've followed your suggestion removing the comment and update PR making the branch clean.
Before reading your suggestion I didn't know that bit of code shouldn't be there.
Again thank you.

Copy link
Contributor

Choose a reason for hiding this comment

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

package-lock.json is still there, can you please remove it as well?

Copy link
Author

Choose a reason for hiding this comment

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

Hi Jenny

Sorry for delay.
I've deleted package-lock.json file.
I typed (git rm --cached package-lock.json) on terminal and committed and pushed to GitHub repo.
It's done.
And I created (.gitignore) file on local git repo and add (package-lock.json) on (.gitignore) so next next time I add, commit and push it doesn't be included onto GitHub upstream repo.
I think it's cleaned now.
Thank you

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

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

// Create a variable to store the dir part of the filePath variable
const dir = filePath.slice(0, lastSlashIndex);

// Create a variable to store the ext part of the variable
const lastDotIndex = filePath.lastIndexOf(".");
const ext = filePath.slice(lastDotIndex);

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

const dir = ;
const ext = ;

// https://www.google.com/search?q=slice+mdn
// https://www.google.com/search?q=slice+mdn
38 changes: 38 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,45 @@ 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

/**
* Step 1: Math.random()

* This generates a random decimal number between 0 (inclusive) and 1 (exclusive).
* Example: 0.3728, 0.9134, etc.

* Step 2: (maximum - minimum + 1)

* This calculates the range of possible numbers you want.
* Here: 100 - 1 + 1 = 100
* So, we’re creating a range that includes both 1 and 100.

* Step 3: Math.random() * (maximum - minimum + 1)

* This augment the random decimal to fit the range.
* Example: If Math.random() it returns 0.3728,
* 0.3728 * 100 = 37.28

* Step 4: Math.floor(...)

* Math.floor() rounds down to the nearest whole number.
* So 37.28 becomes 37.

* Step 5: + minimum

* Because the range started from 0, we add minimum (which is 1) to adjust to the correct range.

* Example: 37 + 1 = 38.

* So what does num represent?
* num is a random integer between 1 (inclusive) and 100 (exclusive).
* Every time the program runs, we get a different number in that range.

*/

27 changes: 25 additions & 2 deletions Sprint-1/2-mandatory-errors/0.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,25 @@
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?

/** The lines that are just instructions or notes for humans and we don’t want the computer to execute them, we turn them into comments.

In JavaScript, there are two ways to write comments:

1. Single-line comment

Use // at the start of a line.
Everything after // is ignored by the computer.

Example:

// This line explains what the code does
const num = 8;

2. Multi-line comment

Use slash asterisk at beginning and asterisk slash at end to wrap several lines.

Example:
The comment wrapping this explanation
*/

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;
// change keyword 'const' to 'let'
let age = 33;
age += 1;

console.log(age);

7 changes: 6 additions & 1 deletion Sprint-1/2-mandatory-errors/2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
// 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}`);
// This is related to variable hoisting.
// const keywork is a block scope and unlike var it's not hoisted automatically.
// The easiest solution is to declare the variable before to use it

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

23 changes: 21 additions & 2 deletions Sprint-1/2-mandatory-errors/3.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
const cardNumber = 4533787178994213;
const last4Digits = cardNumber.slice(-4);
// const cardNumber = 4533787178994213;
// const last4Digits = cardNumber.slice(-4);

// 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

/**
*Prediction: Why won’t this code work?
const cardNumber = 4533787178994213;
const last4Digits = cardNumber.slice(-4);

The issue is that .slice() is a string method, but cardNumber here is a number — not a string.
So when the code runs, JavaScript will say something like:
TypeError: cardNumber.slice is not a function
That’s because .slice() function only works on strings or arrays — and numbers don’t have that method.

Fixing the problem:
To use .slice(), we need to convert the number into a string first:
*/

const cardNumber = 4533787178994213;
const last4Digits = cardNumber.toString().slice(-4);
console.log(last4Digits); // "4213"

20 changes: 18 additions & 2 deletions Sprint-1/2-mandatory-errors/4.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,18 @@
const 12HourClockTime = "20:53";
const 24hourClockTime = "08:53";
// const 12HourClockTime = "20:53";
// const 24hourClockTime = "08:53";

/**
* In javascript variable can't start with a number
* Can contain letters, digits (but not at the start), underscore _, and dollar signs $
*
* const 12HourClockTime = "20:53"; will cause a SyntaxError because variable name can't begin with a number.
*
* To fix it need to chang the name to start with a letter.
*/

const twelveHourClockTime = "08:53";
const twentyFourClockTime = "20:53";

console.log(twelveHourClockTime);
console.log(twentyFourClockTime);

37 changes: 34 additions & 3 deletions Sprint-1/3-mandatory-interpret/1-percentage-change.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,52 @@ 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;

console.log(`The percentage change is ${percentageChange}`);
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

// Function calls and their line numbers
// line 3 - carPrice.replaceAll(",", "") - Callls replaceAll() on the string to remove commas
// line 3 - Number(...) - Converts the resulting string to a number
// line 4 - priceAfterOneYear.replaceAll("," "") - Syntax error here - Intendend to replaceAll() but missing a comma between arguments
// line 8 - console.log(...) - Prints to console
// // Total intended function calls: 5

// 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?

// priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
// Error: SyntaxError: missiong ) after argument list
// Reason:
// There's a missing comma between the arguments of replaceAll.
// The correct syntax should be:
// priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));

// c) Identify all the lines that are variable reassignment statements

// These are the lines where variables that were already declared are assigned a new value:
// carPrice = Number(carPrice.replaceAll(",", "");
// priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
// Reassignments: Lines 3 and 4

// 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?
// These are the lines that are variables declarations:
// let carPrice = "10,000";
// let priceAfterOneYear = "8,543";
// const priceDifference = carPrice - priceAfterOneYear;
// const percentageChange = (priceDifference / carPrice) * 100;

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

// carPrice.replaceAll(",", "") - removes all commas from the string "10,000", then it becomes "10000"
// Number("10000") - Converts the string "10000" into a numeric value 10000.
// Purpose: To convert a formatted currency expression (with commas) into a number that is appropriate for mathematical calculations.
//

52 changes: 52 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,66 @@ 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?
// Each const introduces a new variable.
//
// movieLength
// remainingSeconds
// totalMinutes
// remainingMinutes
// totalHours
// result
// Total variable declarations: 6

// b) How many function calls are there?

// The only function call is:

// Total function call is 1
// console.log(result);

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

// According to the MDN documentation on the remainder (%) operator
// The variable remainingSeconds stores the remainder left over when one movieLength operand is divided by 60

// Interpretation:
// It gives the remaining seconds that don’t make up a full minute.

// d) Interpret line 4, what does the expression assigned to totalMinutes mean?

// const totalMinutes = (movieLength - remainingSeconds) / 60;
// It subtracts the leftover seconds (that couldn’t form a full minute).
// Then divides the remaining seconds by 60.
// In doing so it converts the total movie length into minutes, ignoring any incomplete minute giving the total number of full minutes in the movie.

// e) What do you think the variable result represents? Can you think of a better name for this variable?

// const result = `${totalHours}:${remainingMinutes}:${remainingSeconds}`;

// This combines hours, minutes, and seconds into a single string formatted like H:M:S.
// Example output: "2:26:24"
//
// Better variable names:
// actualTime
// timeAsUsual
// timeExpected

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

// It will work correctly for most positive integers, since it’s just converting seconds into hours, minutes, and seconds using division and remainders.
// However, there are some edge cases:
// If movieLength = 0:
// Output: 0:0:0 Works fine.
// If movieLength < 60 (less than a minute):
// Works fine (e.g., 45 → 0:0:45).
// If movieLength is not an integer (e.g., 87.5):
// Still works, but decimals might appear in remainingSeconds.
// If movieLength is negative:
// The time format breaks giving negative time components.

// Formatting issue:
// The output isn’t padded.
// Example: 2 hours, 5 minutes, 9 seconds → "2:5:9" instead of "02:05:09".
// (Can fix that using function .padStart(2, '0') on each component.)
//
59 changes: 52 additions & 7 deletions Sprint-1/3-mandatory-interpret/3-to-pounds.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
const penceString = "399p";
let penceString = "399p";

const penceStringWithoutTrailingP = penceString.substring(
let penceStringWithoutTrailingP = penceString.substring(
0,
penceString.length - 1
);

const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
const pounds = paddedPenceNumberString.substring(
let paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
let pounds = paddedPenceNumberString.substring(
0,
paddedPenceNumberString.length - 2
);

const pence = paddedPenceNumberString
let pence = paddedPenceNumberString
.substring(paddedPenceNumberString.length - 2)
.padEnd(2, "0");

Expand All @@ -23,5 +23,50 @@ console.log(`£${pounds}.${pence}`);
// You need to do a step-by-step breakdown of each line in this program
// 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"
// To begin we start with
// const penceString = "399p";
//
// Initialises a string variable with the value "399p".
// penceString variable now store the value: "399p"

// const penceStringWithoutTrailingP = penceString.substring(
// 0,
// penceString.length - 1
// );


// What it does: takes a substring of penceString from index 0 up to (but not including) penceString.length - 1.
// And removes the last character (the trailing "p") so we are left with just the numeric part.

// const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");

// What it does: ensures the numeric string has at least 3 characters by adding leading "0" characters.
// The subsequent logic expects at least three digits so we can safely slice off "pounds" (all except the last two digits) and "pence" (last two digits). After that padding can handles small values like "5p" while maintaing correct indexing.
// Result stored: paddedPenceNumberString === "399"

// const pounds = paddedPenceNumberString.substring(
// 0,
// paddedPenceNumberString.length - 2
// );

// What it does: takes the substring from index 0 up to (but not including) the last two characters. Those leading characters represent whole pounds.
// Note: Because of padStart(3, "0"), this always returns at least one character (for values < 100 it returns "0" or more).

// const pence = paddedPenceNumberString
// .substring(paddedPenceNumberString.length - 2)
// .padEnd(2, "0");

// What it does (first part): .substring(length - 2) returns the final two characters (the pence digits).
// What it does (second part): .padEnd(2, "0") ensures the result has at least two characters by adding trailing zeros if needed.
// Example: "399".substring(1) → "99". .padEnd(2,"0") → still "99". So pence === "99".

// console.log(`£${pounds}.${pence}`);

// What it does: prints a formatted pounds-and-pence string and symbol to the console, using template interpolation.
// Why: final result showing what user would expect the representation of the price.
// Example output: £3.99

let numericPence = parseInt(penceString.replace(/\D/g, ""), 10);
pounds = Math.floor(numericPence / 100);
pence = String(numericPence % 100).padStart(2, "0");

Loading