Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
6e357c7
described code in 1-count.js
M-Abdoon Sep 22, 2025
38f900a
Declared a variable that calles the first charachter of each string
M-Abdoon Sep 22, 2025
b82600e
created 2 variables in 3-paths.js , one is to store the fir part of t…
M-Abdoon Sep 22, 2025
dcf3d6f
Manipulated the code several times to get an idea of how the works a…
M-Abdoon Sep 22, 2025
7489fae
converted the lines into comments so the program does not run them
M-Abdoon Sep 22, 2025
88e4a0d
Changed the declaration type of the variable from const to let so we …
M-Abdoon Sep 22, 2025
65ed66e
I put the declaration of the variable on the top so the program knows…
M-Abdoon Sep 22, 2025
b724d4c
Coverted the cardnumber from a number to string so it can be sliced
M-Abdoon Sep 22, 2025
5df6d91
Removed numbers from the begining of the variables' names
M-Abdoon Sep 22, 2025
ecc906b
code identified, error solved, questions answered
M-Abdoon Sep 22, 2025
96f2e35
Exercise 3-time-format solved
M-Abdoon Sep 22, 2025
c1aeb97
exercies 3-to-pounds solved
M-Abdoon Sep 22, 2025
5bf0726
Chrome.md done
M-Abdoon Sep 23, 2025
e7f49b1
objects.md questions answered.
M-Abdoon Sep 23, 2025
27ccab3
Sprint 1 Done!
M-Abdoon Sep 23, 2025
e86db1a
Update 4-random.js -- Removed testing line
M-Abdoon Sep 23, 2025
70edf9c
Update 4-random.js -- returned values to default
M-Abdoon Sep 23, 2025
43a32bb
Update 3.js -- Removed testing line
M-Abdoon Sep 23, 2025
13dbe89
Variable declared twice fixed
M-Abdoon Sep 24, 2025
acaa18f
ignore unintentionally uploaded file
M-Abdoon Sep 24, 2025
076088c
deleted unintentionally uploaded file
M-Abdoon Sep 24, 2025
fa3471c
Update .gitignore
M-Abdoon Sep 25, 2025
667cc7a
Update .gitignore
M-Abdoon Sep 25, 2025
cada88b
added an explaination of the code and what is actually does.
M-Abdoon Sep 29, 2025
762dcdf
Merge branch 'coursework/sprint-1' of https://github.com/M-Abdoon/Mod…
M-Abdoon Sep 29, 2025
21231d3
updated the code explaination
M-Abdoon Sep 29, 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 .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
.DS_Store
.vscode
**/.DS_Store
testing.js
**/.DS_Store
2 changes: 2 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,5 @@ 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
// In line three we assign a new value to the variable "count".
// the = is used to say that this variable should have the value that will be set after the =
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);
initials = initials + middleName.charAt(0);
initials = initials + lastName.charAt(0);

//console.log(initials);

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

9 changes: 7 additions & 2 deletions Sprint-1/1-key-exercises/3-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,19 @@
// (All spaces in the "" line should be ignored. They are purely for formatting.)

const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt";

const lastSlashIndex = filePath.lastIndexOf("/");

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
// Create a variable to store the ext part of the variable

const dir = ;
const ext = ;
const dir = filePath.slice(0, lastSlashIndex + 1);
const ext = filePath.slice(filePath.lastIndexOf("."));

// to test >>
//console.log(`The dir part of filePath is (( ${dir} )) AND the ext part of it is (( ${ext} ))`);
// https://www.google.com/search?q=slice+mdn
15 changes: 14 additions & 1 deletion Sprint-1/1-key-exercises/4-random.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
const minimum = 1;
const maximum = 100;

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

//console.log(num);

Choose a reason for hiding this comment

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

The goal in this task is to offer an explanation of what this code is doing - can you add some comments breaking down what this code is doing bit by bit and then offer a general summary of what is happening?

Copy link
Author

Choose a reason for hiding this comment

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

Thank you.
Yes, I added an explanation of the code, why I made the small change and what the code is actually doing.

// 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. const minimum = 1; : a variable has the name `minimum` declared. it stores hte 1 value. `const` means this var is unchangeable.
// 2. const maximum = 100; a variable has the name `maximum` declared. it stores hte 100 value. `const` means this var is unchangeable.
// 4. num = Math.floor(Math.random() * (maximum - minimum) + 1); : in this line, the variable `num` is declared, it stores a random number
// between 1 and 100. Math.random() generates a random decimal number between 0 and 1 (exclusive).
// then it multiplies this random number by (maximum - minimum) to scales it to a range between 0 and 99 (since maximum is 100 and minimum is 1).
// Adding 1 shifts this range to be between 1 and 100.
// the line had a mistake, it was declared as const num = ... but I changed it to num = ... because const means unchangeable, and here we want to change its value each time we run the code.
// Math.floor() then rounds down the result number to the nearest whole number, and ensures that num is an integer between 1 and 100.

// So the whole code generates a random integer between 1 and 100 (inclusive) and stores it in the variable num.
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 prevent the pc from running those lines by adding the commenting // lines
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;
age = age + 1;
2 changes: 1 addition & 1 deletion Sprint-1/2-mandatory-errors/2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// 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}`);
10 changes: 9 additions & 1 deletion Sprint-1/2-mandatory-errors/3.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
const cardNumber = 4533787178994213;
const cardNumber = "4533787178994213";
const last4Digits = cardNumber.slice(-4);

//console.log(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
// 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

// I assume the code won't work because the value inside "slice()" isn't valid.
// because we should set a valid number or 2 numbers (the first num is to set from where to start,
// the second number is to set where to finish)

// Update: after the first run of the code I realized that CardNumber is actually a number not a string.
// so I think if I convert it into string the code will work properly. No problem with "slice()" value.
4 changes: 2 additions & 2 deletions Sprint-1/2-mandatory-errors/4.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
const 12HourClockTime = "20:53";
const 24hourClockTime = "08:53";
const HourClockTime = "20:53";
const hourClockTime = "08:53";
20 changes: 19 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,29 @@ 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
// -) functions called are:
// Number() ||| carPrice = Number(carPrice.replaceAll(",", ""));
// Number() ||| priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
// replaceAll() ||| carPrice = Number(carPrice.replaceAll(",", ""));
// replaceAll() ||| priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
// console.log()||| console.log(`The percentage change is ${percentageChange}`);

// 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.
// This error is occurring because a , is missing inside the replaceAll() so the two inputs aren't separated.
// I will fix this error by adding , after the first input inside replaceAll()
// replaceAll("," "") Changed to >>
// replaceAll(",", "")

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

// d) Identify all 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?
// it replaces the , that is inside the number with nothing ( removes the , from the number)
18 changes: 17 additions & 1 deletion Sprint-1/3-mandatory-interpret/2-time-format.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const movieLength = 8784; // length of movie in seconds
const movieLength = 86399; // length of movie in seconds

const remainingSeconds = movieLength % 60;
const totalMinutes = (movieLength - remainingSeconds) / 60;
Expand All @@ -12,14 +12,30 @@ 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 declarations.

// b) How many function calls are there?
// There is only 1 function call.

// c) Using documentation, explain what the expression movieLength % 60 represents
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
// this expression divided the movie length (is seconds) by 60 so we get how many minutes the movie length is.
// but since we used % not / that means we only took the reminder left over after dividing the number.
// so basically the code identifies how many seconds will be left over after getting the minutes amount.

// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
// it means that the result of this expression will be the total minutes of the video.
// before that - in line 3 - it took the number of seconds left, and in line 4 it divides the
// movie length ( takes the remaining seconds out ) by 60 because a minute contains 60 seconds.
// so it actually converts the seconds into minutes.

// e) What do you think the variable result represents? Can you think of a better name for this variable?
// The output of the variable result represents time (period of the movie).
// it actually shows the result of converting seconds into readable time format.
// Better to call it (ReadableMovieTime).

// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
// It does work with most if the values, BUT if I put a number that's bigger than 86399, which returns: 23:59:59
// that means it ignores the days, it can be mediated so it can count days, months and years.
// I haven't watched a movie that is longer than a day but just in case :), I think the code should be kind of general sometimes!!
// Also two zeros should be displayed if there're not hours or mins (when I put small numbers that are less that an hour), so it gets more understandable.
22 changes: 20 additions & 2 deletions Sprint-1/3-mandatory-interpret/3-to-pounds.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
const penceString = "399p";
const penceString = "105p";

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

const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
const pounds = paddedPenceNumberString.substring(
0,
Expand All @@ -25,3 +24,22 @@ console.log(`£${pounds}.${pence}`);

// To begin, we can start with
// 1. const penceString = "399p": initialises a string variable with the value "399p"
// 2.
// 3. const penceStringWithoutTrailingP = penceString.substring( : declares new var and assigns the pence string excluding trailing p
// 4. 0, : first value of the function, this is to tell the function to start from the first charachtar in the string
// 5. penceString.length - 1 : second value of the funtion, it takes the string lengs mines 1 (to exclude trailing p)
// 6. ); : closed th funtion.
// 7. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); : it padds the number with 0 from the start (to make number readable and clear)
// 8. const pounds = paddedPenceNumberString.substring( : declares new variable to store pounds, it takes the last two numbers from the number and stores everything that is before the last two numbers because they are pence not pounds.
// 9. 0, : set 0 to start from the first character.
// 10. paddedPenceNumberString.length - 2 : here is where it excludes the last two numbers (the pence).
// 11. ); : closes function.
// 12.
// 13. const pence = paddedPenceNumberString : declares new var to store pence
// 14. .substring(paddedPenceNumberString.length - 2) : identifies the last two numbers (pence) and stores them.
// 15. .padEnd(2, "0"); : to pad the pence with 0 from the end
// 16.
// 17. console.log(`£${pounds}.${pence}`); : to write the result, it prints the two variables, pounds and pence. it adds £ to show that it's pound.



4 changes: 4 additions & 0 deletions Sprint-1/4-stretch-explore/chrome.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ In the Chrome console,
invoke the function `alert` with an input string of `"Hello world!"`;

What effect does calling the `alert` function have?
A small box shows up showing the string "Hello world!".

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?
a small box in the browser shows up and displays a form to fill.

What is the return value of `prompt`?
the return value of the 'prompt' is the string I enter in that box.
7 changes: 7 additions & 0 deletions Sprint-1/4-stretch-explore/objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@ 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?
log() { [native code] }

Now enter just `console` in the Console, what output do you get back?
it shows information that look like variables and values, and starts with something like:
console {debug: ƒ, error: ƒ, info: ƒ, log: ƒ, warn: ƒ, …}

Try also entering `typeof console`

Answer the following questions:

What does `console` store?
Console stores several functions inside it, functions like log(), assert(), debug() and more.

What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean?
`console.log` means that we want to use the function log() that is inside the object (native object) `console`. the dot . means is like navigating from the object to the function inside that object.
so `console.log` means "use the object `console`, then from the functions inside the object use log()".
13 changes: 0 additions & 13 deletions Sprint-2/1-key-errors/0.js

This file was deleted.