Skip to content

London | May 2025 | Houssam Lahlah | Acoursework/sprint 2 #672

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
2dd0a78
explain Increment count variable by 1 after initialization.
HoussamLh Jun 17, 2025
1bc5c74
Create initials variable by extracting first characters of first, mid…
HoussamLh Jun 17, 2025
b16d048
create two variable and Extract directory and file extension parts fr…
HoussamLh Jun 17, 2025
625c114
Add comments explaining how num is calculated as a random integer bet…
HoussamLh Jun 17, 2025
f5522e7
Add explanation for incrementing count variable by 1 after initializa…
HoussamLh Jun 17, 2025
1cf3f70
I believe that I've Done the sprint 1 and this the last exercise.
HoussamLh Jul 6, 2025
b76c5a3
I believe that I've completed the first sprint.
HoussamLh Jul 6, 2025
0748f7c
I've changed const to let for age variable to allow reassignment
HoussamLh Jul 13, 2025
d957dd1
Avoid redeclaring 'str' inside capitalise function
HoussamLh Jul 13, 2025
fcba7aa
Remove redeclaration of parameter and undefined variable usage in con…
HoussamLh Jul 13, 2025
c278bbb
Use valid parameter name instead of number in square function
HoussamLh Jul 13, 2025
335cc37
Avoid redeclaring 'str' inside capitalise function
HoussamLh Jul 15, 2025
2f9d4da
Return value from multiply function instead of just logging it
HoussamLh Jul 15, 2025
bdc5ac9
Correct return statement in sum function to return a + b
HoussamLh Jul 15, 2025
16d6577
Update getLastDigit function to use input parameter instead of consta…
HoussamLh Jul 15, 2025
8796b5b
Implement calculateBMI function with 1 decimal rounding
HoussamLh Jul 15, 2025
1b5f2cf
Convert strings to UPPER_SNAKE_CASE format
HoussamLh Jul 15, 2025
6573f60
Create reusable toPounds function with test cases
HoussamLh Jul 15, 2025
01a1ced
Add inline comments explaining pad and formatTimeDisplay behaviour
HoussamLh Jul 15, 2025
eeff899
Correct 12-hour clock formatting and add comprehensive tests
HoussamLh Jul 15, 2025
f39781a
Revert Sprint-1 folder to CYF's original version
HoussamLh Jul 21, 2025
bce599b
Revert Sprint-1 folder to CYF's original version
HoussamLh Jul 21, 2025
19f296f
convert kg to pounds and round to 2 decimal places
HoussamLh Jul 21, 2025
f63026f
Create reusable toPounds function from Sprint-1 code
HoussamLh Jul 21, 2025
a9c2a21
format 12-hour time consistently with 2-digit hours
HoussamLh Jul 21, 2025
5eb1ab8
Refactor formatAs12HourClock to reduce code duplication
HoussamLh Jul 22, 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
3 changes: 2 additions & 1 deletion Sprint-1/1-key-exercises/1-count.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ 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
// Line 3 Take the current value of count, and then add 1, and store the result back in count.
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);

console.log(initials);


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

5 changes: 3 additions & 2 deletions Sprint-1/1-key-exercises/3-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ 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);
const ext = base.slice(base.lastIndexOf(".") + 1);


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

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

// 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
// 1- In this exercise, you will need to work out what num represents?

// the num gives a random whole number between 1 and 100 like 73, 12, or 100.

// 2- Try breaking down the expression and using documentation to explain what it means
/*

1. Math.random()

Returns a random decimal number between 0 and 1 but never gives 1.0.

Example: 0.24

2. (maximum - minimum + 1)

This gives number of possible values.

Without the +1, we'd only get the difference, not the full count.

for example:

5 - 1 = 4 → but there are actually 5 numbers: 1, 2, 3, 4, 5

So we add +1 to include both ends of the range.

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

This gives a random decimal number between 0 and 100 (like 24, 65 ...)

Because we want the random decimal scaled to the size of the range of possible values.

For example, if we want a number between 1 and 100 (inclusive), there are 100 possible numbers (1, 2, ..., 100).

Multiplying by 100 means the decimal is scaled up to cover all those possibilities before rounding.

4. Math.floor(...)

This rounds the decimal down to the nearest whole number.

Example: Math.floor(78.43) → 78

5. + minimum

we add the minimum to shift the range correctly, and make sure the random number up to start from minimum.

5-1- for example if we remove the + minimum

5-1-1 Math.random() 0.9999 * 99 + 1 → only goes up to 99.999... → max = 99.999... → floor = 100 (but very unlikely)

now 100 becomes very hard to reach, and in many cases, you never get it.

5-1-2 Math.random() 0.00 * 99 + 1 → only goes up to 0... → max = 0... → floor = 0 (now the minimum is 0, and can appears)

conclusion : when we don’t add + minimum, there is a chance that 1 appears, but it’s not the guaranteed minimum anymore —

and the range starts at 0, not 1.

5-2- when we add +minimum

now we make sure the min and max can appear in the final results and make sure the minimum is 1 not 0.

Minimum appears when random = 0

Maximum appears when random is almost 1 (like 0.9999...).

example : Math.random() * 99 + 1 → up to 0.99 → max = 99 → floor = 99 → +1 = 100 (so more possibilities for 100 to appears)

*/

//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
7 changes: 4 additions & 3 deletions Sprint-1/2-mandatory-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// trying to create an age variable and then reassign the value by 1
// Trying to create an age variable and then reassign the value by 1

const age = 33;
age = age + 1;
let age = 33; // Declare a variable called age and assign it the value 33
age = age + 1; // Reassign age to be its current value plus 1
console.log(age); // Output: 34
14 changes: 11 additions & 3 deletions Sprint-1/4-stretch-explore/chrome.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,17 @@ Let's try an example.
In the Chrome console,
invoke the function `alert` with an input string of `"Hello world!"`;

What effect does calling the `alert` function have?
What effect does calling the `alert` function have? It opens a popup message box in the browser with the text:
You must click "OK" to dismiss it before you can do anything else on the page.

Now try invoking the function `prompt` with a string input of `"What is your name?"` - store the return value of your call to `prompt` in an variable called `myName`.

What effect does calling the `prompt` function have?
What is the return value of `prompt`?
What effect does calling the `prompt` function have? It opens a popup input box asking:
What is your name?
and I can enter a response, then click "OK" or "Cancel".

What is the return value of `prompt`? Return value:

If I enter a name (e.g., "Sami") and press OK, it returns the string: "Sami"

If I press Cancel, it returns: null
13 changes: 9 additions & 4 deletions Sprint-1/4-stretch-explore/objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ In this activity, we'll explore some additional concepts that you'll encounter i

Open the Chrome devtools Console, type in `console.log` and then hit enter

What output do you get?
What output do you get? output: ƒ log() { [native code] }

Now enter just `console` in the Console, what output do you get back?
Now enter just `console` in the Console, what output do you get back?output: console {debug: ƒ, error: ƒ, info: ƒ, log: ƒ, warn: ƒ, …}

Try also entering `typeof console`
Try also entering `typeof console` output : object

Answer the following questions:

What does `console` store?
What does `console` store? stores a collection of methods (functions) that are used to log information or debug JavaScript code.

What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean?

This syntax uses dot notation. In JavaScript, the dot . is used to access a property or method of an object.

console is the object.
18 changes: 16 additions & 2 deletions Sprint-2/1-key-errors/0.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Predict and explain first...
// =============> write your prediction here
// =============> // =============> write your prediction here
// I predict the code will throw an error because the variable `str` is being declared twice in the same function scope.


// call the function capitalise with a string input
// interpret the error message and figure out why an error is occurring
Expand All @@ -9,5 +11,17 @@ function capitalise(str) {
return str;
}

// =============> write your explanation here
// =============> write your explanation here
// The function already receives `str` as a parameter.
// Inside the function, it tries to declare `let str = ...`,
// which causes a conflict because JavaScript does not
// allow redeclaring the same variable name in the same scope using `let`.
// This leads to a `SyntaxError: Identifier 'str' has already been declared`.


// =============> write your new code here
// =============> write your new code here
function capitalise(str) {
let capitalisedStr = `${str[0].toUpperCase()}${str.slice(1)}`;
return capitalisedStr;
}
19 changes: 19 additions & 0 deletions Sprint-2/1-key-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
// Predict and explain first...
// =============> write your prediction here
// I predict this program will throw a `SyntaxError` because
// the parameter `decimalNumber` is being redeclared inside the function using `const`.
// Also, the variable `decimalNumber` is being accessed outside the function where it's not defined.


// Why will an error occur when this program runs?
// =============> write your prediction here
Expand All @@ -15,6 +20,20 @@ function convertToPercentage(decimalNumber) {
console.log(decimalNumber);

// =============> write your explanation here
// The function already has a parameter named `decimalNumber`,
// but inside the function, it's trying to declare another
// constant with the same name: `const decimalNumber = 0.5;`.
// JavaScript doesn’t allow redeclaring a variable that already exists in the same scope.
// Also, `console.log(decimalNumber)` is outside the function and `decimalNumber` is not
// defined in the global scope, so that will cause a `ReferenceError`.


// Finally, correct the code to fix the problem
// =============> write your new code here

function convertToPercentage(decimalNumber) {
const percentage = `${decimalNumber * 100}%`;
return percentage;
}

console.log(convertToPercentage(0.5));
13 changes: 13 additions & 0 deletions Sprint-2/1-key-errors/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,32 @@
// Predict and explain first BEFORE you run any code...

// this function should square any number but instead we're going to get an error
// The code will throw a **SyntaxError** because you cannot
// use a number (`3`) as a function parameter name.

// =============> write your prediction of the error here
// SyntaxError: Unexpected number

function square(3) {
return num * num;
}

// =============> write the error message here
// SyntaxError: Unexpected number

// =============> explain this error message here
// In JavaScript, function parameters must be valid variable names (identifiers).
// Using a number like `3` directly as a parameter name is invalid syntax,
// so JavaScript throws a `SyntaxError: Unexpected number`.

// Finally, correct the code to fix the problem

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

function square(num) {
return num * num;
}

console.log(square(3));


14 changes: 14 additions & 0 deletions Sprint-2/2-mandatory-debug/0.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// Predict and explain first...

// =============> write your prediction here
// I predict that the console will log `320` first (from inside the function),
// but then the message will say: "The result of multiplying 10 and 32 is undefined".

// Explanation:

function multiply(a, b) {
console.log(a * b);
Expand All @@ -9,6 +13,16 @@ function multiply(a, b) {
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);

// =============> write your explanation here
// The function `multiply` logs the result of `a * b`, but does not return it.
// When it's used inside a template literal, JavaScript evaluates `multiply(10, 32)` as `undefined`,
// because the function has no return value. That's why we get:
// `The result of multiplying 10 and 32 is undefined` — even though `320` is logged separately.

// Finally, correct the code to fix the problem
// =============> write your new code here

function multiply(a, b) {
return a * b;
}

console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
18 changes: 16 additions & 2 deletions Sprint-2/2-mandatory-debug/1.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
// Predict and explain first...
// =============> write your prediction here

// =============> write your prediction here
// I predict that this will print: "The sum of 10 and 32 is undefined"
// because the function has a return statement with no value.

// Explanation:
function sum(a, b) {
return;
a + b;
// =============> write your explanation here
// The `return;` statement ends the function early, so `a + b` is never reached.
// In JavaScript, any code after a bare `return;` is ignored (unreachable code).
// That's why the function returns `undefined`, not the actual sum.
}

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

// =============> write your explanation here
// Finally, correct the code to fix the problem
// =============> write your new code here
function sum(a, b) {
return a + b;
}

console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
// Now the function returns the correct result: 42

23 changes: 21 additions & 2 deletions Sprint-2/2-mandatory-debug/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

// Predict the output of the following code:
// =============> Write your prediction here
// I predict that all three log statements will output: "The last digit of 42 is 3", "105 is 3", "806 is 3"
// Because the getLastDigit function doesn’t use the input — it always returns the last digit of the constant
// `num = 103`.

// Original Code
const num = 103;

function getLastDigit() {
Expand All @@ -15,10 +19,25 @@ console.log(`The last digit of 806 is ${getLastDigit(806)}`);

// Now run the code and compare the output to your prediction
// =============> write the output here
// The actual output is:
// The last digit of 42 is 3
// The last digit of 105 is 3
// The last digit of 806 is 3

// Explain why the output is the way it is
// =============> write your explanation here
// The function `getLastDigit` doesn't take any parameter, and it always uses the fixed variable `num = 103`.
// So regardless of the input in the log statements, the function always returns the last digit of 103, which is "3".

// Finally, correct the code to fix the problem
// =============> write your new code here
function getLastDigit(number) {
return number.toString().slice(-1);
}

console.log(`The last digit of 42 is ${getLastDigit(42)}`); // 2
console.log(`The last digit of 105 is ${getLastDigit(105)}`); // 5
console.log(`The last digit of 806 is ${getLastDigit(806)}`); // 6

// Now the function works correctly by taking a number as input and returning its last digit.

// This program should tell the user the last digit of each number.
// Explain why getLastDigit is not working properly - correct the problem
26 changes: 10 additions & 16 deletions Sprint-2/3-mandatory-implement/1-bmi.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
// Below are the steps for how BMI is calculated

// The BMI calculation divides an adult's weight in kilograms (kg) by their height in metres (m) squared.

// For example, if you weigh 70kg (around 11 stone) and are 1.73m (around 5 feet 8 inches) tall, you work out your BMI by:

// squaring your height: 1.73 x 1.73 = 2.99
// dividing 70 by 2.99 = 23.41
// Your result will be displayed to 1 decimal place, for example 23.4.
function calculateBMI(weight, height) {
// Square the height (height in meters)
const heightSquared = height * height;

// You will need to implement a function that calculates the BMI of someone based off their weight and height
// Divide weight by height squared to get BMI
const bmi = weight / heightSquared;

// Given someone's weight in kg and height in metres
// Then when we call this function with the weight and height
// It should return their Body Mass Index to 1 decimal place
// Return the BMI rounded to 1 decimal place
return bmi.toFixed(1); // toFixed returns a string, which is fine unless you need it as a number
}

function calculateBMI(weight, height) {
// return the BMI of someone based off their weight and height
}
// Example usage:
console.log(calculateBMI(70, 1.73)); // Output: "23.4"
Loading