Skip to content
Open
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
1189fcd
Add age calculation functionality and HTML structure for age input
HadiVahidi20 Sep 29, 2025
78b6a33
Refactor age calculator layout and improve form structure
HadiVahidi20 Sep 29, 2025
ea977e5
addWnetListener Example added
HadiVahidi20 Sep 29, 2025
22c0fee
Refactor age calculator layout and improve form structure
HadiVahidi20 Sep 30, 2025
c346f52
percentage exersice added
HadiVahidi20 Sep 30, 2025
ea0fca9
Enhance percentage exercise layout and add area calculation functiona…
HadiVahidi20 Sep 30, 2025
5df448f
Add area calculation alert to percentage exercise
HadiVahidi20 Oct 1, 2025
ef4f642
Add comments to clarify count variable increment logic
HadiVahidi20 Oct 1, 2025
efa5aa8
second exercise is done using charAt(index)
HadiVahidi20 Oct 1, 2025
aa951b4
Implement dir and ext variable assignments in file path exercise
HadiVahidi20 Oct 2, 2025
921ba5a
Refactor random number generation logic and enhance comments for clar…
HadiVahidi20 Oct 2, 2025
e32fceb
change the codes to comments in 0.js
HadiVahidi20 Oct 2, 2025
3b87801
mandatory-errors 2 is completed
HadiVahidi20 Oct 2, 2025
24ee904
Fix variable initialization error by moving console.log after declara…
HadiVahidi20 Oct 2, 2025
d51395c
Fix last4Digits assignment by converting cardNumber to string before …
HadiVahidi20 Oct 2, 2025
14e15a6
percentage exercise is completed
HadiVahidi20 Oct 2, 2025
711385f
the movie length exercise is done
HadiVahidi20 Oct 2, 2025
e82c680
Update penceString value and enhance console logging for clarity in 3…
HadiVahidi20 Oct 3, 2025
b28011e
Enhance examples in objects.md to clarify console usage and output
HadiVahidi20 Oct 3, 2025
6c7a0b7
Implement to24hourtime function and add initial HTML test page
HadiVahidi20 Oct 9, 2025
0cf3390
yse there 5, one in console.log
HadiVahidi20 Nov 7, 2025
aa53b91
correct the answer in the 2-time-format.js
HadiVahidi20 Nov 7, 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: 4 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,7 @@ 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 is updating the value of count by adding 1 to its current value, so count now equals 1 and every time we run the code it will increment by 1.
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 = `${firstName.charAt(0)}${middleName.charAt(0)}${lastName.charAt(0)}`;

console.log(initials);

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

10 changes: 7 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,11 @@ 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 = filePath.slice(filePath.lastIndexOf("."));

// https://www.google.com/search?q=slice+mdn
console.log(`The dir part of ${filePath} is ${dir}`);

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

// https://www.google.com/search?q=slice+mdn
26 changes: 26 additions & 0 deletions Sprint-1/1-key-exercises/4-random.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,31 @@ 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

// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor
//

//Mach.random() - generates a random number between 0 (inclusive) and 1 (exclusive):
const num1=Math.random();
console.log(num1);

const num3=(maximum - minimum + 1);
//(maximum - minimum + 1) - calculates the range of numbers we want (in this case, 100 - 1 + 1 = 100)
//so by adding this to our random number we are scaling it to be between 0 and 100
console.log(num3);
const num2=Math.random()*(maximum - minimum + 1);
console.log(num2);
//until this point we have a random number between 0 (inclusive) and 100 (exclusive)but is can be a decimal number
// Math.floor() - rounds down to the nearest whole number, so we now have a random integer between 0 and 99

const num5 = Math.floor(Math.random() * (maximum - minimum + 1)) ;
console.log(`it suppose to be a rounded number from 0-99 ${num5}`);

//finally By adding 1, the number will be between 1 and 100, including both.

console.log(`it suppose to be a rounded number from 1-100 ${num}`);

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

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

// we can use comments to ignore these lines of code, in javascript we use // for single line comments and /* */ for multi line comments
18 changes: 18 additions & 0 deletions Sprint-1/2-mandatory-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
// trying to create an age variable and then reassign the value by 1



const age = 33;
age = age + 1;
console.log(age);
/*the constant variable cannot be reassigned a new value
so in lin 6 we will get an error because it can not reassign the age variable with a new value of age + 1 which in this case is 34
here is the error message we will get:/home/cyf/CYF/ITP/Module-Structuring-and-Testing-Data/Sprint-1/2-mandatory-errors/1.js:6
age = age + 1;
^

TypeError: Assignment to constant variable.

to fix this error we can use let instead of const because let variable can be reassigned a new value*/

let age2 = 33;
age2 = age2 + 1;
console.log(age2);

// now it will work fine and the output will be 34 and every time we run the code it will increase by 1
14 changes: 13 additions & 1 deletion Sprint-1/2-mandatory-errors/2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
// 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}`);
//console.log(`I was born in ${cityOfBirth}`);
const cityOfBirth = "Bolton";

/*/home/cyf/CYF/ITP/Module-Structuring-and-Testing-Data/Sprint-1/2-mandatory-errors/2.js:4
console.log(`I was born in ${cityOfBirth}`);
^

ReferenceError: Cannot access 'cityOfBirth' before initialization

this error is because we are trying to access the variable cityOfBirth before it is initialized and assigned a value.
the console.log should be after the variable declaration and assignment

*/
console.log(`I was born in ${cityOfBirth}`);
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);
console.log(`The last 4 digits of my card number are ${last4Digits}`);

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



//it doesn't work because the slice method is used for strings and arrays but cardNumber is a number so it doesn't have the slice method.



// 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
// to fix this error we can convert the number to a string using the toString() method before applying the slice method
9 changes: 7 additions & 2 deletions Sprint-1/2-mandatory-errors/4.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
const 12HourClockTime = "20:53";
const 24hourClockTime = "08:53";
const twelveHourClockTime = "08:53";
const twentyFourHourClockTime = "20:53";

//tha variable names are cannot start with a number
// so the variable name 12HourClockTime is not valid because it starts with a number
// to fix this error we can change the variable name to twelveHourClockTime and as is not relevant to the time format
// so we can swap the variable names.
46 changes: 44 additions & 2 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,63 @@ 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

/*There are four function calls in total: two in the line

Choose a reason for hiding this comment

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

Are you sure there are only 4?


carPrice = Number(carPrice.replaceAll(",", ""));

and two in the line

priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));

In each line, one function is nested inside the other, so both lines contain two function calls each.*/



// 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("," ""));
^^^

SyntaxError: missing ) after argument list
the error is because a missing comma in the replaceAll method argument list
*/


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



/*carPrice = Number(carPrice.replaceAll(",", ""));
priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
these two lines are variable reassignment statements because we are reassigning a new value to the existing variables carPrice and priceAfterOneYear.*/

// d) Identify all the lines that are variable declarations


/*let carPrice = "10,000";
let priceAfterOneYear = "8,543";
const priceDifference = carPrice - priceAfterOneYear;
const percentageChange = (priceDifference / carPrice) * 100;

these four lines are variable declaration statements because we are declaring new variables:
carPrice, priceAfterOneYear, priceDifference and percentageChange using let and const keywords.*/



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

/*first removes all commas from the string carPrice using replaceAll(",", ""), and then converts the resulting string into a number using Number().*/
47 changes: 46 additions & 1 deletion Sprint-1/3-mandatory-interpret/2-time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,59 @@ 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 six variable declarations in this program:
1. movieLength
2. remainingSeconds
3. totalMinutes
4. remainingMinutes
5. totalHours
6. result
*/

// b) How many function calls are there?

/*There are no function calls in this code. Everything here is using operators and expressions, not calling functions.*/

Choose a reason for hiding this comment

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

Are you sure there are no functions? I think in both this and the previous task you are missing the same function call.

Copy link
Author

Choose a reason for hiding this comment

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

you are right, I forgot to count the console.log as a function call in both codes. thank you


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

/*The % operator in JavaScript is the remainder operator. It divides the left-hand number by the right-hand number and returns the remainder.

So in this case:

movieLength % 60

divides movieLength (8784) by 60 and gives the remaining seconds, which is 24.*/


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

/*The expression

totalMinutes = (movieLength - remainingSeconds) / 60;

subtracts the leftover seconds from the total seconds so that we get a whole number of minutes.
Then it divides by 60 to convert seconds into minutes without any decimal part.*/


// e) What do you think the variable result represents? Can you think of a better name for this variable?
/*The variable result represents the length of the movie in the format hours:minutes:seconds.

A better name could be something like:

movieDurationFormatted

formattedDuration

movieLengthHMS (HMS = hours, minutes, seconds)*/

// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer,
/*Yes, it works for all non-negative values:

If the movie is less than an hour, totalHours is 0, so we get 0:MM:SS.

If the movie is less than a minute, both totalHours and remainingMinutes are 0, so we get 0:0:SS.

For larger movies, it correctly calculates hours, minutes, and seconds.

// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
The only exception would be negative values, which aren’t realistic for a movie length.*/
66 changes: 54 additions & 12 deletions Sprint-1/3-mandatory-interpret/3-to-pounds.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,69 @@
const penceString = "399p";
const penceString = "3679p";

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

console.log(penceStringWithoutTrailingP);

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

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

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

console.log(pounds);

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

console.log(pence);

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



// This program takes a string representing a price in pence
// The program then builds up a string representing the price in pounds

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

/*1. const penceString = "399p";

We create a variable called penceString and give it the value "399p".

This is the price in pence, written as text.

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

We remove the last letter "p" from the string.

Now we only have the numbers, for example "399".

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

We make sure the string has at least 3 characters by adding zeros at the start if needed.

Example: "50" becomes "050" and "5" becomes "005".

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

We take all characters except the last two.

These characters are the pounds. Example: "399" → "3" pounds.

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

We take the last two characters. These are the pence.

We add a zero at the end if needed to always have two digits. Example: "5" → "05".

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

We show the price in pounds and pence.

Example: "399p" → £3.99, "50p" → £0.50. */
10 changes: 10 additions & 0 deletions Sprint-1/4-stretch-explore/objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,21 @@ Open the Chrome devtools Console, type in `console.log` and then hit enter

What output do you get?

ƒ log() { [native code] }

Now enter just `console` in the Console, what output do you get back?

console {debug: ƒ, error: ƒ, info: ƒ, log: ƒ, warn: ƒ, …}

Try also entering `typeof console`
'object'

Answer the following questions:

What does `console` store?

console stores different functions (like log, assert, warn, error) that you can use to interact with the console.


What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean?
console.log("Hello") means: Look in the console object, find the log function, and run it with "Hello" as the argument.
Loading
Loading