Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
6278aca
adding a h2
AbdennourHachemi Sep 16, 2026
1e2d9f3
Adding the answer to exercise1
AbdennourHachemi Sep 19, 2026
05b468c
solving the exercise
AbdennourHachemi Sep 19, 2026
d1507f1
solving the exercise using slice method
AbdennourHachemi Sep 19, 2026
dc792ba
solving exercise 4-random
AbdennourHachemi Sep 19, 2026
cfceef2
solving exercise 0.js
AbdennourHachemi Sep 19, 2026
dc92e00
solving exercise 1.js
AbdennourHachemi Sep 19, 2026
6f3c7bb
solving exercise 2.js
AbdennourHachemi Sep 19, 2026
da76479
solving exercise 3.js
AbdennourHachemi Sep 19, 2026
8fc0ed8
solving exercise 4.js
AbdennourHachemi Sep 19, 2026
51551e1
sovling exercise 1-percentage-change
AbdennourHachemi Sep 19, 2026
98b99fe
update solution
AbdennourHachemi Sep 19, 2026
7e1fd30
solving exercise 2-time-format
AbdennourHachemi Sep 19, 2026
e3bf82a
solving exercise 3-to-pounds
AbdennourHachemi Sep 19, 2026
c6f0fd0
solve chrom.md
AbdennourHachemi Sep 19, 2026
0290b7c
solving objects exercise
AbdennourHachemi Sep 19, 2026
ed20ed5
Remove accidentally tracked education-blog/education-blog submodule
AbdennourHachemi Sep 20, 2026
5329549
correcting exercise 2-time-format
AbdennourHachemi Sep 20, 2026
1f6a0a3
Further correction exercise 2-time-format
AbdennourHachemi Sep 20, 2026
d386bfb
correcting exercise 1.js
AbdennourHachemi Sep 20, 2026
b1e0fc1
fixing issues in excersie 4-random
AbdennourHachemi Sep 20, 2026
33458e1
correcting exercise 3-paths.js
AbdennourHachemi Sep 20, 2026
21c5ff7
fixing .gitignore issue
AbdennourHachemi Sep 20, 2026
3754064
correct comment on line 27 4-random.js exercise
AbdennourHachemi Sep 20, 2026
c4041a0
Correcting comment on line 27
AbdennourHachemi Sep 20, 2026
a727eb0
correction
AbdennourHachemi Sep 20, 2026
5a76622
adding a line at the end that says what num is
AbdennourHachemi Sep 21, 2026
c861b14
applying Prittier formating for the files
AbdennourHachemi Sep 21, 2026
ce7a6d0
add num answer
AbdennourHachemi Sep 21, 2026
d7636e9
Further correction of file format
AbdennourHachemi Sep 21, 2026
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
5 changes: 5 additions & 0 deletions Sprint-2/1-key-exercises/1-count.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ 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 3 the code is incrmenting the variable "count" by 1 , the operator "=" is assigning a new value to "count" by adding 1.
*/
4 changes: 3 additions & 1 deletion Sprint-2/1-key-exercises/2-initials.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const 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.

const initials = ``;
const initials = `${firstName.charAt(0)}${middleName.charAt(0)}${lastName.charAt(0)}`;

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

console.log(initials);
14 changes: 11 additions & 3 deletions Sprint-2/1-key-exercises/3-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@ 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);
/*correction : slice(0,lastSlashIndex); is the correct method to extract the dir path
filePath.slice(start, end) => 0 represents the character 0 of the filePath String put 1 will skip the first charchter.
*/

// https://www.google.com/search?q=slice+mdn
const ext = filePath.slice(filePath.lastIndexOf(".") + 1);

// https://www.google.com/search?q=slice+mdn

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

console.log(`The ext part of a variable file.txt is ${ext}`);
15 changes: 15 additions & 0 deletions Sprint-2/1-key-exercises/4-random.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,18 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
// 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

console.log(num);

//First operation
//num is generating a random dicimal number with method Math.random() between 0 and 1 result eg :0.3948605

//Second operation
//The generated number is multiplied by the range+1 which is between 1-100 result eg 39.48605

//Third operation
//num is rounded down to the nearset whole number using the method Math.floor restult eg 39.48605 => 39

//Last operation is to add the "minimum" (in this case it's 1 or it can be changed to any changed number e.g 10) this will shift the random number so it starts counting from minimum, instead of from zero.
//eg . num was 39 => 40
//num is a random whole number from 1 to 100.
4 changes: 2 additions & 2 deletions Sprint-2/2-mandatory-errors/0.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
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?*/
9 changes: 8 additions & 1 deletion Sprint-2/2-mandatory-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
// trying to create an age variable and then reassign the value by 1

const age = 33;
let age = 33;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The fix is right and the file runs. This section also asks you to interpret the error and explain why it happened, and there is nothing written down here. You did that well in 2.js, 3.js and 4.js, so the same again. What did node print before you changed const to let?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good, the message and the reason are both written down now.

age = age + 1;

/*
Answer : The Error is : TypeError: Assignment to constant variable.
Constants in JavaScript can't be reassigned to correct this we have to change the varible type from const => let.

*/
console.log(age);
6 changes: 5 additions & 1 deletion Sprint-2/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}`);
//Answer : the error was that CitOfBirth vaiable was declared after the method cosole .log()
//The solution is to declare it before calling it.

const cityOfBirth = "Bolton";

console.log(`I was born in ${cityOfBirth}`);
14 changes: 13 additions & 1 deletion Sprint-2/2-mandatory-errors/3.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
const cardNumber = 4533787178994213;
const last4Digits = cardNumber.slice(-4);
const last4Digits = cardNumber.toString().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 : The slice method is used with String data type. here we have cardNumber varible with type Number.
Running the code will give a TypeError : cardNumber.slice is not a function
The solution is to convert numbe to string, There are three posibility:
String(cardNumber)
cardNumber.toString()
`${cardNumber}`

*/

console.log(last4Digits);
8 changes: 6 additions & 2 deletions Sprint-2/2-mandatory-errors/4.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
const 12HourClockTime = "8:53pm";
const 24hourClockTime = "20:53";
const HourClockTime12 = "8:53pm";
const hourClockTime24 = "20:53";

/*
the naming of of the varibles is not correct varible should not start with a number
*/
46 changes: 44 additions & 2 deletions Sprint-2/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,52 @@ 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

// 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?
/*
Solution to a)

There are 5 function calls in this file:
-------------|-----------------| --------|
1 | Number() | line 4 |
2 | replaceAll() | line 4 |
3 | Number() | line 5 |
4 | replaceAll() | line 5 |
5 | console.log() | line 10 |
------------------------------------------


*/

// 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?
/*
Solution to b)
After running the code the terminal gives SyntaxError: missing ) after argument list BUT the actual error is not having a comma in line 5 in the replaceAll methode as it needs two arguments
eplaceAll("," "") => should be eplaceAll("," , "")
*/
// c) Identify all the lines that are variable reassignment statements
/*
Solution to c)
Variable reassignment statements lines are:

line 4 : carPrice = Number(carPrice.replaceAll(",", ""));
line 5 : priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
*/

// d) Identify all the lines that are variable declarations
/*
Solution to d)
Variable declarations lines are:
line 1 :let carPrice = "10,000";
line 2 :let priceAfterOneYear = "8,543";
line 7 :const priceDifference = carPrice - priceAfterOneYear;
c line 8 :const percentageChange = (priceDifference / carPrice) * 100;

*/

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

/*
Solution to e)
The expresssion Number(carPrice.replaceAll(",","")) is removing the comma "," in CarPrice i.e from 10,000 to 10000 which is stored
in String type , removing the comma will insure the mathimatical operation will go normal when converted to type Number.

*/
43 changes: 42 additions & 1 deletion Sprint-2/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 = 90.5; // length of movie in seconds

const remainingSeconds = movieLength % 60;
const totalMinutes = (movieLength - remainingSeconds) / 60;
Expand All @@ -12,14 +12,55 @@ 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?
/************************************************** */
/* Solution a): There are 6 varibale declarations */
/************************************************* */

// b) How many function calls are there?
/**************************************************/
/* Solution b): */
/* There is only one fuction call (console.log() */
/*********************************************** */

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

/*********************************************************************************************************************/
/*Solution c): */
/* The operator (%) called Modulo returns the remainder left over when one operand is divided by a second operand */
/* In this expamle it gives the time remainder of the movie in seconds */
/*********************************************************************************************************************/

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

/****************************************************************************************************************************************************************************/
/* Solution d): */
/* The totalMinutes expression is calaculated first by subtrackting the lengh of movie by the reminder of seconds which rounds down the nearst minutes */
/* Since we know the total number of seconds that are multiple of 60 we can can calculate the total number of minutes by dividing it over 60 since 1 minute is 60 seconds */
/* This way we have the Movie total exact number of miutes. */
/****************************************************************************************************************************************************************************/

// e) What do you think the variable result represents? Can you think of a better name for this variable?
/*********************************************************************************************/
/* Solution e): */
/* The variable result represents the exact lenght of the movie in Hours + Minutes + Seconds */
/* A better name for variable result could be : extctMovieLength */
/*********************************************************************************************/

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

/***************************************************************************************************************************************************************/
/* Solution e): */
/* movieLength = 0 => exactMovieLength = 0:0:0 */
/* movieLength = 60 => exactMovieLength = 0:1:0 */
/* movieLength = 3676 => exactMovieLength = 1:1:16 */
/* movieLength = -3600 => exactMoveLenght = -1:0:0 */
/* movieLength = 90000 => exactMoveLenght = 25:0:0 */
/* */
/* This code Could be better: */
/* - giving a negative value for movieLength will result in a negative clock: so there could have message that reject negative numbers. */
/* - The program should have represented Hours/Min/Sec in this format 00:00:00 so each time should be represented with 2 digits. */
/* - 25 hours exeeds 24 hours which represents a day so a variable total days could be added to represent time in days. */
/* -Values with dicimal numbers will return the clock showing dicimal numbers this should be rounded up or down to the nearst time with an integer number */
/* */
/**********************************************************************************************************************************************************/
11 changes: 9 additions & 2 deletions Sprint-2/3-mandatory-interpret/3-to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ const penceString = "399p";

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

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

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

const pence = paddedPenceNumberString
.substring(paddedPenceNumberString.length - 2)
Expand All @@ -25,3 +27,8 @@ console.log(`£${pounds}.${pence}`);

// To begin, we can start with
// 1. const penceString = "399p": initialises a string variable with the value "399p"
// 2. penceStringWithoutTrailingP = penceString.substring( 0, penceString.length - 1): This line of code slice the penceString varible by removing the "p" character from it.
// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0") : This line of code adds "0" if lenght of penceStringWithoutTrailingP is less then 3 i.e e value is "1" => it will convert it to"001" or ifthe value is "22" it will convert it to "022".
// 4. const pounds = paddedPenceNumberString.substring( 0, paddedPenceNumberString.length - 2); : This line of code extract and store the value of pound from paddedPenceNumberString using the substring method since £1 = 100 pences => any number in the hudered position i.e third character from the right onwards has a value of £.
// 5. const pence = paddedPenceNumberString .substring(paddedPenceNumberString.length - 2) .padEnd(2, "0");: This line of code extract and store the value of pences paddedPenceNumberString using the substring method => instead of starting from the left it start from the right moving two positions then it adds "0"in case the pences value is less then 10.
// 6. console.log(`£${pounds}.${pence}`): This line of code prints the final result in £ and pences in nice readable way => £3.99
5 changes: 5 additions & 0 deletions Sprint-2/4-stretch-explore/chrome.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ Let's try an example.
In the Chrome console, invoke the function `alert` with one argument, the string `"Hello world!"`;

What effect does calling the `alert` function have?
Answer : it will brings a popup with alert message "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?
What is the return value of `prompt`?

Answer: calling the `prompt` function will bring up a dialog box with a field to put an answer

The return value of `prompt is the variable `myName`
94 changes: 94 additions & 0 deletions Sprint-2/4-stretch-explore/objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,106 @@ 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?
Answer : an object : log() { [native code] }

Now enter just `console` in the Console, what output do you get back?
Answer : an object
console {debug: ƒ, error: ƒ, info: ƒ, log: ƒ, warn: ƒ, …}
assert
:
ƒ assert()
clear
:
ƒ clear()
context
:
ƒ context()
count
:
ƒ count()
countReset
:
ƒ countReset()
createTask
:
ƒ createTask()
debug
:
ƒ debug()
dir
:
ƒ dir()
dirxml
:
ƒ dirxml()
error
:
ƒ error()
group
:
ƒ group()
groupCollapsed
:
ƒ groupCollapsed()
groupEnd
:
ƒ groupEnd()
info
:
ƒ info()
log
:
ƒ log()
memory
:
MemoryInfo {totalJSHeapSize: 19300000, usedJSHeapSize: 18200000, jsHeapSizeLimit: 3760000000}
profile
:
ƒ profile()
profileEnd
:
ƒ profileEnd()
table
:
ƒ table()
time
:
ƒ time()
timeEnd
:
ƒ timeEnd()
timeLog
:
ƒ timeLog()
timeStamp
:
ƒ timeStamp()
trace
:
ƒ trace()
warn
:
ƒ warn()
Symbol(Symbol.toStringTag)
:
"console"
[[Prototype]]
:
Object

Try also entering `typeof console`

Answer : object
Answer the following questions:

What does `console` store?
Answer : The console object does not permanently store data; instead, it provides an interface to record, display, and inspect temporary logs, warnings, and errors in the environment's debugging tool or terminal.
What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean?

Answer :

The console.log() is a method that accepts any value and outputs that the given value to the console

The console.assert() is a static method that writes an error message to the console if the assertion is false. If the assertion is true, nothing happens.

The `.` is dot notation — it access the methods that belongs to the console object. such as log, assert, error .... ext
Loading