Skip to content
Open
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
25 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
4818ddd
Correct a function with let defined inside it
carlosyabreu Nov 7, 2025
992f376
Change the local variable to be called from global scope
carlosyabreu Nov 7, 2025
607ca58
Change a literal numerical value as parameter for a variable expect b…
carlosyabreu Nov 7, 2025
79b52ed
Commit 0.js and 1.js files
carlosyabreu Nov 7, 2025
6b17b68
Change the function to display the last digit correctly
carlosyabreu Nov 7, 2025
e29954a
Correct the BMI function and the necessary explanation
carlosyabreu Nov 7, 2025
9577ac5
Change small letter into capital letter
carlosyabreu Nov 7, 2025
2b746b1
Different display of pounds
carlosyabreu Nov 7, 2025
886d971
Test of function at different scenarios
carlosyabreu Nov 7, 2025
d34a28d
Display time in usual format
carlosyabreu Nov 7, 2025
da83341
Delete Sprint-1 folder
carlosyabreu Nov 8, 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.

7 changes: 7 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,10 @@ 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 increase the count variable by 1 then assign the result in right hand side to count variable
*/

console.log('Value of count variable: ', 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 = ``;
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
40 changes: 40 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,47 @@ 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 scales the random decimal to the range.
* Example: If Math.random() 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 shift it to the correct range.

* Example: 37 + 1 = 38.

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

* Running it several times — you’ll see numbers like 27, 99, 7, 100, etc.

*/

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

/** If you have lines that are just instructions or notes for humans and you don’t want the computer to execute them, you can 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 \ /* ... *\ / to wrap several lines.

Example:
This section is just instructions
The computer will ignore everything between these symbols

const num = 5;

*/

6 changes: 5 additions & 1 deletion 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;
// change keyword 'const' to 'let'
let age = 33;
age = age + 1;

console.log(age);

6 changes: 5 additions & 1 deletion Sprint-1/2-mandatory-errors/2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// 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 a very common JavaScript error related to variable hoisting and the temporal dead zone.
// Simply declare the variable before you use it

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

29 changes: 27 additions & 2 deletions Sprint-1/2-mandatory-errors/3.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,34 @@
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() 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:

Now it works!
*/

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 names can't begin with a number.
*
* To fix it by changing the name to start with a letter.
*/

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

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

32 changes: 31 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 @@ -13,10 +13,40 @@ console.log(`The percentage change is ${percentageChange}`);

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

// These are the lines where variables are first introduced:
// 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 string (with commas) into a number that can be used for mathematical calculations.

65 changes: 65 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,79 @@ 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 calls: 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 remainder operator returns the remainder left over when one operand is divided by a second operand.
// So:
// movieLength % 60
// means “the remainder when movieLength is divided by 60.”
// Interpretation:
// It gives you the remaining seconds that don’t make up a full minute.
// For example, if the movie length were 125 seconds:
// 125 % 60 = 5, so there are 5 seconds left over after 2 full minutes.
// Purpose: Extract the leftover seconds after converting total seconds into minutes.

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

// const totalMinutes = (movieLength - remainingSeconds) / 60;
// This line:
// Subtracts the leftover seconds (that couldn’t form a full minute).

// Divides the remaining seconds by 60.
// Meaning:
// Converts the total movie length into minutes, ignoring any incomplete minute.
// So it gives 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"
// Meaning: It represents the formatted time duration of the movie.
// Better variable names:
// formattedDuration
// timeString
// movieTime
// durationInHMS

// 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 logic breaks — you’d get 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 with .padStart(2, '0') on each component.)

// Summary:
// It works for positive whole numbers, but for negative or non-integer inputs, or if you need formatted time, adjustments are needed.

Loading
Loading