From 877e0dec76c8d7c2886c86c194c9249c54239248 Mon Sep 17 00:00:00 2001 From: Rawan Almutairi Date: Mon, 28 Sep 2026 12:56:21 +0100 Subject: [PATCH 1/6] I worked in all the excercises --- Sprint-2/1-key-exercises/1-count.js | 1 + Sprint-2/1-key-exercises/2-initials.js | 14 +++++- Sprint-2/1-key-exercises/3-paths.js | 49 ++++++++++++++++--- Sprint-2/1-key-exercises/4-random.js | 13 +++++ Sprint-2/2-mandatory-errors/0.js | 6 ++- Sprint-2/2-mandatory-errors/1.js | 8 ++- Sprint-2/2-mandatory-errors/2.js | 2 + Sprint-2/2-mandatory-errors/3.js | 1 + Sprint-2/2-mandatory-errors/4.js | 8 ++- .../1-percentage-change.js | 14 ++++-- .../3-mandatory-interpret/2-time-format.js | 12 +++-- Sprint-2/3-mandatory-interpret/3-to-pounds.js | 30 ++++++++++++ 12 files changed, 136 insertions(+), 22 deletions(-) diff --git a/Sprint-2/1-key-exercises/1-count.js b/Sprint-2/1-key-exercises/1-count.js index 117bcb2b6..d0686196f 100644 --- a/Sprint-2/1-key-exercises/1-count.js +++ b/Sprint-2/1-key-exercises/1-count.js @@ -4,3 +4,4 @@ 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 +//a variable is initialised and assigned a value zero, than it was reassigned additing 1 to its value. \ No newline at end of file diff --git a/Sprint-2/1-key-exercises/2-initials.js b/Sprint-2/1-key-exercises/2-initials.js index 964c9563c..a749c3066 100644 --- a/Sprint-2/1-key-exercises/2-initials.js +++ b/Sprint-2/1-key-exercises/2-initials.js @@ -5,6 +5,18 @@ 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 = ``; // https://www.google.com/search?q=get+first+character+of+string+mdn + +const initials = `${firstName[0]}${middleName[0]}${lastName[0]}`; + +console.log(initials); // Output: CKJ + + + + + + + + diff --git a/Sprint-2/1-key-exercises/3-paths.js b/Sprint-2/1-key-exercises/3-paths.js index ab90ebb28..e1b3c3cda 100644 --- a/Sprint-2/1-key-exercises/3-paths.js +++ b/Sprint-2/1-key-exercises/3-paths.js @@ -9,15 +9,52 @@ // (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 = ; + +// https://www.google.com/search?q=slice+mdn + +// from here start my explaination of the code I see for education purposes. +// this is a file system that allows users to manipulate what files they see and what information they omit, and they use string +//methods to do that +// most common methods developers use to manipulate the files are included in this file Sprint-2\1-key-exercises\manipulating files.txt + +// in this example the string methods are used to manipulate the file system + 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}`); +// a variable is created to store the file path of a file in the file system +//const lastSlashIndex = filePath.lastIndexOf("/"); +// a variable is created and identified to find the last occurance of the "/" character in the filePath variable, which is used to separate directories and files in a file system +//const base = filePath.slice(lastSlashIndex + 1); +// a variable is created and identified to extract the base part of the filePath variable, which is the name of the file and its extension, by using the slice method +//console.log(`The base part of ${filePath} is ${base}`); +// console.log is used to print the base part of the filePath variable to the console, which is the name of the file and its extension // 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 lastSlashIndex = filePath.lastIndexOf("/"); +// here we have the variable lastslashIndex already created and identified its position +// stores the position or (index) of "/" in filePath, so this "/" is used as a symbol that storers the number index or a place that seprate dir from base +const dir = filePath.slice(0, lastSlashIndex); +console.log(dir); +// we show our result in the console +const lastDotIndex = filePath.lastIndexOf('.'); +// we create a variable and assign its value using the indexOf to be from the dot location +const ext = filePath.slice(lastDotIndex); +// we create a variable where we assign its value using the slice method to be from the dot only -// https://www.google.com/search?q=slice+mdn \ No newline at end of file +console.log(ext) +// we print our result in the console +//slice(startIndex, endIndex) +// means, start here and stop here. we are doing this to seprate the dir from base so we need to tell it where to start and where to end, hence that is why we use slice method, +// my comments needs correcting to look profissional -_- \ No newline at end of file diff --git a/Sprint-2/1-key-exercises/4-random.js b/Sprint-2/1-key-exercises/4-random.js index 292f83aab..8a2a984df 100644 --- a/Sprint-2/1-key-exercises/4-random.js +++ b/Sprint-2/1-key-exercises/4-random.js @@ -7,3 +7,16 @@ 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 + + +//here starts my learning + +// first const minimun, const maximum are the variables +// = the assignmen operator +// what comes after = is what the variable will store +// Math.floor is a method and here we are telling it that its argument is to use the random method +// and multiply the result before rounding with the maximum and minimum variables we created +// * is a multiplication operator +// to understand what is going on we need to understand what the floor and random methods do +//Math.floor (rounds down to the nearest whole number) and than pass it to Math.floor +// we are asking the program to round whatever result we have to the nearest whole number \ No newline at end of file diff --git a/Sprint-2/2-mandatory-errors/0.js b/Sprint-2/2-mandatory-errors/0.js index cf6c5039f..4c2b55901 100644 --- a/Sprint-2/2-mandatory-errors/0.js +++ b/Sprint-2/2-mandatory-errors/0.js @@ -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? \ No newline at end of file +//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 use slash to comment it. So the computer doesn't excute the text. \ No newline at end of file diff --git a/Sprint-2/2-mandatory-errors/1.js b/Sprint-2/2-mandatory-errors/1.js index 7a43cbea7..e3cc83bd0 100644 --- a/Sprint-2/2-mandatory-errors/1.js +++ b/Sprint-2/2-mandatory-errors/1.js @@ -1,4 +1,10 @@ // trying to create an age variable and then reassign the value by 1 -const age = 33; +let age = 33; age = age + 1; + +//we change the variable declaration and reassign its value +// variable declaration keywords +// const can't be used to reassign a value +// let can be used to reassign a value + diff --git a/Sprint-2/2-mandatory-errors/2.js b/Sprint-2/2-mandatory-errors/2.js index e09b89831..021a1842b 100644 --- a/Sprint-2/2-mandatory-errors/2.js +++ b/Sprint-2/2-mandatory-errors/2.js @@ -3,3 +3,5 @@ console.log(`I was born in ${cityOfBirth}`); const cityOfBirth = "Bolton"; + +// the variable was declared after the print function so the program doesn't know what is cityofBirth. Therefore it can't perform the print function or excuted before declaring the variable diff --git a/Sprint-2/2-mandatory-errors/3.js b/Sprint-2/2-mandatory-errors/3.js index ec101884d..fb1ebb348 100644 --- a/Sprint-2/2-mandatory-errors/3.js +++ b/Sprint-2/2-mandatory-errors/3.js @@ -7,3 +7,4 @@ const last4Digits = cardNumber.slice(-4); // 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 +// in this case its a reference error the program is trying to access a value that wasn't declared. In this case a variable. diff --git a/Sprint-2/2-mandatory-errors/4.js b/Sprint-2/2-mandatory-errors/4.js index 5f86c730b..45b029112 100644 --- a/Sprint-2/2-mandatory-errors/4.js +++ b/Sprint-2/2-mandatory-errors/4.js @@ -1,2 +1,6 @@ -const 12HourClockTime = "8:53pm"; -const 24hourClockTime = "20:53"; +const TwelveHourClockTime = "8:53pm"; +const TwentyFourHourClockTime = "20:53"; +// an identifier or keyword can't follow a numeric literal. We fix this by writing the numbers in words format + +//const 12HourClockTime = "8:53pm"; +//const 24hourClockTime = "20:53"; diff --git a/Sprint-2/3-mandatory-interpret/1-percentage-change.js b/Sprint-2/3-mandatory-interpret/1-percentage-change.js index e24ecb8e1..36383953c 100644 --- a/Sprint-2/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-2/3-mandatory-interpret/1-percentage-change.js @@ -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; @@ -11,12 +11,16 @@ 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 +// a) How many function calls are there in this file? Write down all the lines where a function call is made +//5 FUNCTION calls. Line 4, 5, 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? - +//The error is coming from line 5, column 61. Thhere is nothing seprating the two indexes. A comma can be used to seprate them. // c) Identify all the lines that are variable reassignment statements - +//Two lines 4 and 5 // d) Identify all the lines that are variable declarations - +//four lines 1,2,7,8 // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? +//The replace.all method is used to include the car price and the price after one year of depreciation. + //The purpose of the expression is to take the price string and search for every comma and replace it + // we are saying replace this "," , with this "" and because of the empty string it means without a comma \ No newline at end of file diff --git a/Sprint-2/3-mandatory-interpret/2-time-format.js b/Sprint-2/3-mandatory-interpret/2-time-format.js index 47d239558..ca7dfb9c4 100644 --- a/Sprint-2/3-mandatory-interpret/2-time-format.js +++ b/Sprint-2/3-mandatory-interpret/2-time-format.js @@ -12,14 +12,16 @@ 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? - +// 6 declarations // b) How many function calls are there? - +// 1 function call in line 10 // c) Using documentation, explain what the expression movieLength % 60 represents // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators - +// "operator returns the remainder left over when one operand is divided by a second operand. It always takes the sign of the dividend." // d) Interpret line 4, what does the expression assigned to totalMinutes mean? - +// it means the number of minutes in a film is calculated by calculating the number of seconds in the film // e) What do you think the variable result represents? Can you think of a better name for this variable? - +//the variable result represesnt the length of the film in hours,minutes,and seconds. A better name would be movie time. // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer +// However, it doesn't work when the leading number of a decimal is zero like this 08784 because it interpreted as octal literal and 8 can't work in octal numeration +//"The octal number system is a base-8 math and computing system that uses only eight digits: 0, 1, 2, 3, 4, 5, 6, and 7" \ No newline at end of file diff --git a/Sprint-2/3-mandatory-interpret/3-to-pounds.js b/Sprint-2/3-mandatory-interpret/3-to-pounds.js index 60c9ace69..1146b3395 100644 --- a/Sprint-2/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-2/3-mandatory-interpret/3-to-pounds.js @@ -25,3 +25,33 @@ console.log(`£${pounds}.${pence}`); // To begin, we can start with // 1. const penceString = "399p": initialises a string variable with the value "399p" +// 2. const penceStringWithoutTrailingP = penceString.substring( + // 0, + // penceString.length - 1 +//); +//INITIALISES A STRING VARIABLE AND ASSIGN ITS VALUE USEING THE penceString.substring +// so what happins is penceString.substring is using the value from the application or calculation of ( + //0, + // penceString.length - 1 +//); +// we are tillING IT TO start from the first inex (0) and not to include index 3 which penceString.length than use the operator - to subtract 1 +// we intialise a string variable const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); and assign its value to be +//const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); +//const pounds = paddedPenceNumberString.substring( + // 0, + //paddedPenceNumberString.length - 2 +//); +// we assign the value to be starting with MINUMUM LENGTH IS 3 CHARACTERS than if not ADD THE VALUE 0 TO THE BEGINNING +// we initialise a variable const pounds and assign its value to be the value from using paddedPenceNumberString.substring +//paddedPenceNumberString.substring value is found by starting from the first index WITH LENGTH 3 and ending with paddedPenceNumberString.length subtracted by the operator 2 + +// IN THIS LINE const pence = paddedPenceNumberString +const pence = paddedPenceNumberString + .substring(paddedPenceNumberString.length - 2) + .padEnd(2, "0"); + +console.log(`£${pounds}.${pence}`); +// we initialise a string variable and assign its value to be the paddedPenceNumberString variable with the value from using the substring method +// the substring method is calculated by using the length property or the value of paddedPenceNumberString subtracting it by 2 using operator - +// than using the method .padEnd to specify that if the length is not two add the value 0 +// last we ask the console to print the values in pounds and pence \ No newline at end of file From 4629b0fcbdc4572c0a586ceb1742b90884f58352 Mon Sep 17 00:00:00 2001 From: Rawan Almutairi Date: Mon, 28 Sep 2026 13:53:01 +0100 Subject: [PATCH 2/6] worked on the sprint --- Form-Controls/Prototype-Code.html | 84 ++++++++ Form-Controls/index.html | 64 +++++- Form-Controls/style.css | 20 ++ .../1-key-exercises/manipulating files.txt | 185 ++++++++++++++++++ Sprint-2/2-mandatory-errors/error types.txt | 56 ++++++ 5 files changed, 403 insertions(+), 6 deletions(-) create mode 100644 Form-Controls/Prototype-Code.html create mode 100644 Form-Controls/style.css create mode 100644 Sprint-2/1-key-exercises/manipulating files.txt create mode 100644 Sprint-2/2-mandatory-errors/error types.txt diff --git a/Form-Controls/Prototype-Code.html b/Form-Controls/Prototype-Code.html new file mode 100644 index 000000000..fce6e6506 --- /dev/null +++ b/Form-Controls/Prototype-Code.html @@ -0,0 +1,84 @@ + + + + + + + + + My form exercise + + + + + + +
+

Product Pick

+
+
+
+ + Enter your name: + + + + + + + +

Choose your T-shirt color:

+ +

please select a color:

+

+ +
+ +
+ +
+

+ + +Select your T-shirt size: +
+ + + +
+ +

+ + Enter your email: + +

+ + + +
+
+
+ +

Rawan@

+
+ + \ No newline at end of file diff --git a/Form-Controls/index.html b/Form-Controls/index.html index 74b591ffc..4d463ce75 100644 --- a/Form-Controls/index.html +++ b/Form-Controls/index.html @@ -4,6 +4,7 @@ My form exercise + @@ -13,15 +14,66 @@

Product Pick

- - + + Enter your name: + + + + + + + +

Choose your T-shirt color:

+ +

please select a color:

+

+ +
+ +
+ +
+

+ + + + + + + +
+ +

+ + Enter your email: + +

+ + + +
+
-

By HOMEWORK SOLUTION

+

Rawan@

- + + + diff --git a/Form-Controls/style.css b/Form-Controls/style.css new file mode 100644 index 000000000..fc8a5d656 --- /dev/null +++ b/Form-Controls/style.css @@ -0,0 +1,20 @@ + + + body { color: #141414; + + background-color: #6aa57e; + + font-family: Georgia; + + + + +h1{ + +font family: "sans-serif"; +color: rgba(15, 15, 15, 0.267); +background-color: #f5eeda; +text-align: center; +font-family: Cambria, Cochin, Georgia, Times, 'Times New Roman', serif; + +} \ No newline at end of file diff --git a/Sprint-2/1-key-exercises/manipulating files.txt b/Sprint-2/1-key-exercises/manipulating files.txt new file mode 100644 index 000000000..13ca3e26f --- /dev/null +++ b/Sprint-2/1-key-exercises/manipulating files.txt @@ -0,0 +1,185 @@ + + +======================================== +NODE.JS FILE SYSTEM CHEAT SHEET +======================================== + +MENTAL MODEL + +String Methods + ↓ +Path Module + ↓ +File System Module (fs) + ↓ +Actual Files on Disk + + +======================================== +1. STRING METHODS +======================================== + +Purpose: +Manipulate path strings manually. + +Example Path: + +/Users/rawan/project/file.txt + + +slice() + +Purpose: +Extract part of a string. + +Example: +filePath.slice(7) + + +split() + +Purpose: +Break a string into pieces. + +Example: +filePath.split("/") + +Result: +["", "Users", "rawan", "project", "file.txt"] + + +includes() + +Purpose: +Check if text exists. + +Example: +filePath.includes("rawan") + + +startsWith() + +Purpose: +Check beginning of string. + +Example: +filePath.startsWith("/Users") + + +endsWith() + +Purpose: +Check ending of string. + +Example: +filePath.endsWith(".txt") + + +indexOf() + +Purpose: +Find first occurrence. + +Example: +filePath.indexOf("/") + + +lastIndexOf() + +Purpose: +Find last occurrence. + +Example: +filePath.lastIndexOf("/") + + +replace() + +Purpose: +Replace text. + +Example: +filePath.replace(".txt", ".pdf") + + +substring() + +Purpose: +Extract part of a string. + +Example: +filePath.substring(7, 12) + + +trim() + +Purpose: +Remove whitespace. + +Example: +filePath.trim() + + + +======================================== +2. PATH MODULE +======================================== + +Import: + +const path = require("path"); + +Purpose: +Manipulate file paths safely. + + +path.basename() + +Purpose: +Get filename. + +Example: + +path.basename("/Users/rawan/file.txt") + +Result: + +file.txt + + +path.dirname() + +Purpose: +Get directory path. + +Example: + +path.dirname("/Users/rawan/file.txt") + +Result: + +/Users/rawan + + +path.extname() + +Purpose: +Get extension. + +Example: + +path.extname("file.txt") + +Result: + +.txt + + +path.join() + +Purpose: +Join path pieces. + +Example: + +path.join("users", "rawan) \ No newline at end of file diff --git a/Sprint-2/2-mandatory-errors/error types.txt b/Sprint-2/2-mandatory-errors/error types.txt new file mode 100644 index 000000000..809b55b9a --- /dev/null +++ b/Sprint-2/2-mandatory-errors/error types.txt @@ -0,0 +1,56 @@ +JAVASCRIPT ERROR TYPES + +1. SyntaxError + + * JavaScript cannot understand the syntax or structure of the code. + * Think: "Did I write the code correctly?" + * Example: const x = ; + +2. ReferenceError + + * You are trying to access a variable, function, or other reference that is not available. + * Think: "Can JavaScript find/access what I'm referring to?" + * Example: console.log(name); when name has not been declared. + +3. TypeError + + * You are trying to perform an operation that is not valid for the value's type. + * Think: "Am I using this value in a way that is allowed?" + * Example: 33.toUpperCase(); + +4. RangeError + + * A value is outside the range of values that an operation allows. + * Example: new Array(-1); + +5. URIError + + * An invalid URI-related operation has occurred. + * Example: decodeURIComponent("%"); + +6. EvalError + + * Related to the eval() function. + * Rarely encountered in modern JavaScript. + +7. AggregateError + + * Represents multiple errors grouped together. + * Can occur with certain Promise operations, such as Promise.any(). + +MAIN ONES TO REMEMBER + +SyntaxError → Code syntax/structure is invalid. + +ReferenceError → JavaScript cannot access the thing being referenced. + +TypeError → The value exists, but you are using it incorrectly for its type. + +RangeError → A value is outside an allowed range. + +URIError → An invalid URI operation occurred. + +EvalError → Related to eval(); rarely encountered. + +AggregateError → Multiple errors are grouped into one error. + From 379880413d9dc3f48c2c6a765cb383d38f20e316 Mon Sep 17 00:00:00 2001 From: Rawan Almutairi Date: Mon, 28 Sep 2026 13:56:35 +0100 Subject: [PATCH 3/6] fixed some issues with the files --- Form-Controls/style.css | 4 ++-- git-collaboration/index.html | 0 2 files changed, 2 insertions(+), 2 deletions(-) create mode 100644 git-collaboration/index.html diff --git a/Form-Controls/style.css b/Form-Controls/style.css index fc8a5d656..3fa433582 100644 --- a/Form-Controls/style.css +++ b/Form-Controls/style.css @@ -1,4 +1,4 @@ - + body { color: #141414; @@ -11,7 +11,7 @@ h1{ -font family: "sans-serif"; +font-family: sans-serif; color: rgba(15, 15, 15, 0.267); background-color: #f5eeda; text-align: center; diff --git a/git-collaboration/index.html b/git-collaboration/index.html new file mode 100644 index 000000000..e69de29bb From cee94d168ed8778d32245ef4249d7e7035aa466c Mon Sep 17 00:00:00 2001 From: Rawan0-0 Date: Mon, 28 Sep 2026 14:06:20 +0100 Subject: [PATCH 4/6] Delete Sprint-2/1-key-exercises directory --- Sprint-2/1-key-exercises/1-count.js | 7 - Sprint-2/1-key-exercises/2-initials.js | 22 --- Sprint-2/1-key-exercises/3-paths.js | 60 ------ Sprint-2/1-key-exercises/4-random.js | 22 --- .../1-key-exercises/manipulating files.txt | 185 ------------------ 5 files changed, 296 deletions(-) delete mode 100644 Sprint-2/1-key-exercises/1-count.js delete mode 100644 Sprint-2/1-key-exercises/2-initials.js delete mode 100644 Sprint-2/1-key-exercises/3-paths.js delete mode 100644 Sprint-2/1-key-exercises/4-random.js delete mode 100644 Sprint-2/1-key-exercises/manipulating files.txt diff --git a/Sprint-2/1-key-exercises/1-count.js b/Sprint-2/1-key-exercises/1-count.js deleted file mode 100644 index d0686196f..000000000 --- a/Sprint-2/1-key-exercises/1-count.js +++ /dev/null @@ -1,7 +0,0 @@ -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 -//a variable is initialised and assigned a value zero, than it was reassigned additing 1 to its value. \ No newline at end of file diff --git a/Sprint-2/1-key-exercises/2-initials.js b/Sprint-2/1-key-exercises/2-initials.js deleted file mode 100644 index a749c3066..000000000 --- a/Sprint-2/1-key-exercises/2-initials.js +++ /dev/null @@ -1,22 +0,0 @@ -const firstName = "Creola"; -const middleName = "Katherine"; -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 = ``; - -// https://www.google.com/search?q=get+first+character+of+string+mdn - -const initials = `${firstName[0]}${middleName[0]}${lastName[0]}`; - -console.log(initials); // Output: CKJ - - - - - - - - diff --git a/Sprint-2/1-key-exercises/3-paths.js b/Sprint-2/1-key-exercises/3-paths.js deleted file mode 100644 index e1b3c3cda..000000000 --- a/Sprint-2/1-key-exercises/3-paths.js +++ /dev/null @@ -1,60 +0,0 @@ -// The diagram below shows the different names for parts of a file path on a Unix operating system - -// ┌─────────────────────┬────────────┐ -// │ dir │ base │ -// ├──────┬ ├──────┬─────┤ -// │ root │ │ name │ ext │ -// " / home/user/dir / file .txt " -// └──────┴──────────────┴──────┴─────┘ - -// (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 = ; - -// https://www.google.com/search?q=slice+mdn - -// from here start my explaination of the code I see for education purposes. -// this is a file system that allows users to manipulate what files they see and what information they omit, and they use string -//methods to do that -// most common methods developers use to manipulate the files are included in this file Sprint-2\1-key-exercises\manipulating files.txt - -// in this example the string methods are used to manipulate the file system - -const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt"; -// a variable is created to store the file path of a file in the file system -//const lastSlashIndex = filePath.lastIndexOf("/"); -// a variable is created and identified to find the last occurance of the "/" character in the filePath variable, which is used to separate directories and files in a file system -//const base = filePath.slice(lastSlashIndex + 1); -// a variable is created and identified to extract the base part of the filePath variable, which is the name of the file and its extension, by using the slice method -//console.log(`The base part of ${filePath} is ${base}`); -// console.log is used to print the base part of the filePath variable to the console, which is the name of the file and its extension - -// Create a variable to store the dir part of the filePath variable -// Create a variable to store the ext part of the variable - -const lastSlashIndex = filePath.lastIndexOf("/"); -// here we have the variable lastslashIndex already created and identified its position -// stores the position or (index) of "/" in filePath, so this "/" is used as a symbol that storers the number index or a place that seprate dir from base -const dir = filePath.slice(0, lastSlashIndex); -console.log(dir); -// we show our result in the console -const lastDotIndex = filePath.lastIndexOf('.'); -// we create a variable and assign its value using the indexOf to be from the dot location -const ext = filePath.slice(lastDotIndex); -// we create a variable where we assign its value using the slice method to be from the dot only - -console.log(ext) -// we print our result in the console -//slice(startIndex, endIndex) -// means, start here and stop here. we are doing this to seprate the dir from base so we need to tell it where to start and where to end, hence that is why we use slice method, -// my comments needs correcting to look profissional -_- \ No newline at end of file diff --git a/Sprint-2/1-key-exercises/4-random.js b/Sprint-2/1-key-exercises/4-random.js deleted file mode 100644 index 8a2a984df..000000000 --- a/Sprint-2/1-key-exercises/4-random.js +++ /dev/null @@ -1,22 +0,0 @@ -const minimum = 1; -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 - - -//here starts my learning - -// first const minimun, const maximum are the variables -// = the assignmen operator -// what comes after = is what the variable will store -// Math.floor is a method and here we are telling it that its argument is to use the random method -// and multiply the result before rounding with the maximum and minimum variables we created -// * is a multiplication operator -// to understand what is going on we need to understand what the floor and random methods do -//Math.floor (rounds down to the nearest whole number) and than pass it to Math.floor -// we are asking the program to round whatever result we have to the nearest whole number \ No newline at end of file diff --git a/Sprint-2/1-key-exercises/manipulating files.txt b/Sprint-2/1-key-exercises/manipulating files.txt deleted file mode 100644 index 13ca3e26f..000000000 --- a/Sprint-2/1-key-exercises/manipulating files.txt +++ /dev/null @@ -1,185 +0,0 @@ - - -======================================== -NODE.JS FILE SYSTEM CHEAT SHEET -======================================== - -MENTAL MODEL - -String Methods - ↓ -Path Module - ↓ -File System Module (fs) - ↓ -Actual Files on Disk - - -======================================== -1. STRING METHODS -======================================== - -Purpose: -Manipulate path strings manually. - -Example Path: - -/Users/rawan/project/file.txt - - -slice() - -Purpose: -Extract part of a string. - -Example: -filePath.slice(7) - - -split() - -Purpose: -Break a string into pieces. - -Example: -filePath.split("/") - -Result: -["", "Users", "rawan", "project", "file.txt"] - - -includes() - -Purpose: -Check if text exists. - -Example: -filePath.includes("rawan") - - -startsWith() - -Purpose: -Check beginning of string. - -Example: -filePath.startsWith("/Users") - - -endsWith() - -Purpose: -Check ending of string. - -Example: -filePath.endsWith(".txt") - - -indexOf() - -Purpose: -Find first occurrence. - -Example: -filePath.indexOf("/") - - -lastIndexOf() - -Purpose: -Find last occurrence. - -Example: -filePath.lastIndexOf("/") - - -replace() - -Purpose: -Replace text. - -Example: -filePath.replace(".txt", ".pdf") - - -substring() - -Purpose: -Extract part of a string. - -Example: -filePath.substring(7, 12) - - -trim() - -Purpose: -Remove whitespace. - -Example: -filePath.trim() - - - -======================================== -2. PATH MODULE -======================================== - -Import: - -const path = require("path"); - -Purpose: -Manipulate file paths safely. - - -path.basename() - -Purpose: -Get filename. - -Example: - -path.basename("/Users/rawan/file.txt") - -Result: - -file.txt - - -path.dirname() - -Purpose: -Get directory path. - -Example: - -path.dirname("/Users/rawan/file.txt") - -Result: - -/Users/rawan - - -path.extname() - -Purpose: -Get extension. - -Example: - -path.extname("file.txt") - -Result: - -.txt - - -path.join() - -Purpose: -Join path pieces. - -Example: - -path.join("users", "rawan) \ No newline at end of file From 14c6110982fec237cdd34bb9aa7817a8527b636f Mon Sep 17 00:00:00 2001 From: Rawan0-0 Date: Mon, 28 Sep 2026 14:06:42 +0100 Subject: [PATCH 5/6] Delete Sprint-2/2-mandatory-errors directory --- Sprint-2/2-mandatory-errors/0.js | 4 -- Sprint-2/2-mandatory-errors/1.js | 10 ---- Sprint-2/2-mandatory-errors/2.js | 7 --- Sprint-2/2-mandatory-errors/3.js | 10 ---- Sprint-2/2-mandatory-errors/4.js | 6 --- Sprint-2/2-mandatory-errors/error types.txt | 56 --------------------- 6 files changed, 93 deletions(-) delete mode 100644 Sprint-2/2-mandatory-errors/0.js delete mode 100644 Sprint-2/2-mandatory-errors/1.js delete mode 100644 Sprint-2/2-mandatory-errors/2.js delete mode 100644 Sprint-2/2-mandatory-errors/3.js delete mode 100644 Sprint-2/2-mandatory-errors/4.js delete mode 100644 Sprint-2/2-mandatory-errors/error types.txt diff --git a/Sprint-2/2-mandatory-errors/0.js b/Sprint-2/2-mandatory-errors/0.js deleted file mode 100644 index 4c2b55901..000000000 --- a/Sprint-2/2-mandatory-errors/0.js +++ /dev/null @@ -1,4 +0,0 @@ -//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 use slash to comment it. So the computer doesn't excute the text. \ No newline at end of file diff --git a/Sprint-2/2-mandatory-errors/1.js b/Sprint-2/2-mandatory-errors/1.js deleted file mode 100644 index e3cc83bd0..000000000 --- a/Sprint-2/2-mandatory-errors/1.js +++ /dev/null @@ -1,10 +0,0 @@ -// trying to create an age variable and then reassign the value by 1 - -let age = 33; -age = age + 1; - -//we change the variable declaration and reassign its value -// variable declaration keywords -// const can't be used to reassign a value -// let can be used to reassign a value - diff --git a/Sprint-2/2-mandatory-errors/2.js b/Sprint-2/2-mandatory-errors/2.js deleted file mode 100644 index 021a1842b..000000000 --- a/Sprint-2/2-mandatory-errors/2.js +++ /dev/null @@ -1,7 +0,0 @@ -// 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"; - -// the variable was declared after the print function so the program doesn't know what is cityofBirth. Therefore it can't perform the print function or excuted before declaring the variable diff --git a/Sprint-2/2-mandatory-errors/3.js b/Sprint-2/2-mandatory-errors/3.js deleted file mode 100644 index fb1ebb348..000000000 --- a/Sprint-2/2-mandatory-errors/3.js +++ /dev/null @@ -1,10 +0,0 @@ -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 -// in this case its a reference error the program is trying to access a value that wasn't declared. In this case a variable. diff --git a/Sprint-2/2-mandatory-errors/4.js b/Sprint-2/2-mandatory-errors/4.js deleted file mode 100644 index 45b029112..000000000 --- a/Sprint-2/2-mandatory-errors/4.js +++ /dev/null @@ -1,6 +0,0 @@ -const TwelveHourClockTime = "8:53pm"; -const TwentyFourHourClockTime = "20:53"; -// an identifier or keyword can't follow a numeric literal. We fix this by writing the numbers in words format - -//const 12HourClockTime = "8:53pm"; -//const 24hourClockTime = "20:53"; diff --git a/Sprint-2/2-mandatory-errors/error types.txt b/Sprint-2/2-mandatory-errors/error types.txt deleted file mode 100644 index 809b55b9a..000000000 --- a/Sprint-2/2-mandatory-errors/error types.txt +++ /dev/null @@ -1,56 +0,0 @@ -JAVASCRIPT ERROR TYPES - -1. SyntaxError - - * JavaScript cannot understand the syntax or structure of the code. - * Think: "Did I write the code correctly?" - * Example: const x = ; - -2. ReferenceError - - * You are trying to access a variable, function, or other reference that is not available. - * Think: "Can JavaScript find/access what I'm referring to?" - * Example: console.log(name); when name has not been declared. - -3. TypeError - - * You are trying to perform an operation that is not valid for the value's type. - * Think: "Am I using this value in a way that is allowed?" - * Example: 33.toUpperCase(); - -4. RangeError - - * A value is outside the range of values that an operation allows. - * Example: new Array(-1); - -5. URIError - - * An invalid URI-related operation has occurred. - * Example: decodeURIComponent("%"); - -6. EvalError - - * Related to the eval() function. - * Rarely encountered in modern JavaScript. - -7. AggregateError - - * Represents multiple errors grouped together. - * Can occur with certain Promise operations, such as Promise.any(). - -MAIN ONES TO REMEMBER - -SyntaxError → Code syntax/structure is invalid. - -ReferenceError → JavaScript cannot access the thing being referenced. - -TypeError → The value exists, but you are using it incorrectly for its type. - -RangeError → A value is outside an allowed range. - -URIError → An invalid URI operation occurred. - -EvalError → Related to eval(); rarely encountered. - -AggregateError → Multiple errors are grouped into one error. - From 43def6d89143e7ee2dd53f0183dc494dd3558721 Mon Sep 17 00:00:00 2001 From: Rawan0-0 Date: Mon, 28 Sep 2026 14:07:01 +0100 Subject: [PATCH 6/6] Delete Sprint-2/3-mandatory-interpret directory --- .../1-percentage-change.js | 26 --------- .../3-mandatory-interpret/2-time-format.js | 27 --------- Sprint-2/3-mandatory-interpret/3-to-pounds.js | 57 ------------------- 3 files changed, 110 deletions(-) delete mode 100644 Sprint-2/3-mandatory-interpret/1-percentage-change.js delete mode 100644 Sprint-2/3-mandatory-interpret/2-time-format.js delete mode 100644 Sprint-2/3-mandatory-interpret/3-to-pounds.js diff --git a/Sprint-2/3-mandatory-interpret/1-percentage-change.js b/Sprint-2/3-mandatory-interpret/1-percentage-change.js deleted file mode 100644 index 36383953c..000000000 --- a/Sprint-2/3-mandatory-interpret/1-percentage-change.js +++ /dev/null @@ -1,26 +0,0 @@ -let carPrice = "10,000"; -let priceAfterOneYear = "8,543"; - -carPrice = Number(carPrice.replaceAll(",", "")); -priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); - -const priceDifference = carPrice - priceAfterOneYear; -const percentageChange = (priceDifference / carPrice) * 100; - -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 -//5 FUNCTION calls. Line 4, 5, 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? -//The error is coming from line 5, column 61. Thhere is nothing seprating the two indexes. A comma can be used to seprate them. -// c) Identify all the lines that are variable reassignment statements -//Two lines 4 and 5 -// d) Identify all the lines that are variable declarations -//four lines 1,2,7,8 -// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? -//The replace.all method is used to include the car price and the price after one year of depreciation. - //The purpose of the expression is to take the price string and search for every comma and replace it - // we are saying replace this "," , with this "" and because of the empty string it means without a comma \ No newline at end of file diff --git a/Sprint-2/3-mandatory-interpret/2-time-format.js b/Sprint-2/3-mandatory-interpret/2-time-format.js deleted file mode 100644 index ca7dfb9c4..000000000 --- a/Sprint-2/3-mandatory-interpret/2-time-format.js +++ /dev/null @@ -1,27 +0,0 @@ -const movieLength = 8784; // length of movie in seconds - -const remainingSeconds = movieLength % 60; -const totalMinutes = (movieLength - remainingSeconds) / 60; - -const remainingMinutes = totalMinutes % 60; -const totalHours = (totalMinutes - remainingMinutes) / 60; - -const result = `${totalHours}:${remainingMinutes}:${remainingSeconds}`; -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? -// 6 declarations -// b) How many function calls are there? -// 1 function call in line 10 -// c) Using documentation, explain what the expression movieLength % 60 represents -// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators -// "operator returns the remainder left over when one operand is divided by a second operand. It always takes the sign of the dividend." -// d) Interpret line 4, what does the expression assigned to totalMinutes mean? -// it means the number of minutes in a film is calculated by calculating the number of seconds in the film -// e) What do you think the variable result represents? Can you think of a better name for this variable? -//the variable result represesnt the length of the film in hours,minutes,and seconds. A better name would be movie time. -// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer -// However, it doesn't work when the leading number of a decimal is zero like this 08784 because it interpreted as octal literal and 8 can't work in octal numeration -//"The octal number system is a base-8 math and computing system that uses only eight digits: 0, 1, 2, 3, 4, 5, 6, and 7" \ No newline at end of file diff --git a/Sprint-2/3-mandatory-interpret/3-to-pounds.js b/Sprint-2/3-mandatory-interpret/3-to-pounds.js deleted file mode 100644 index 1146b3395..000000000 --- a/Sprint-2/3-mandatory-interpret/3-to-pounds.js +++ /dev/null @@ -1,57 +0,0 @@ -const penceString = "399p"; - -const penceStringWithoutTrailingP = penceString.substring( - 0, - penceString.length - 1 -); - -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(`£${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" -// 2. const penceStringWithoutTrailingP = penceString.substring( - // 0, - // penceString.length - 1 -//); -//INITIALISES A STRING VARIABLE AND ASSIGN ITS VALUE USEING THE penceString.substring -// so what happins is penceString.substring is using the value from the application or calculation of ( - //0, - // penceString.length - 1 -//); -// we are tillING IT TO start from the first inex (0) and not to include index 3 which penceString.length than use the operator - to subtract 1 -// we intialise a string variable const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); and assign its value to be -//const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); -//const pounds = paddedPenceNumberString.substring( - // 0, - //paddedPenceNumberString.length - 2 -//); -// we assign the value to be starting with MINUMUM LENGTH IS 3 CHARACTERS than if not ADD THE VALUE 0 TO THE BEGINNING -// we initialise a variable const pounds and assign its value to be the value from using paddedPenceNumberString.substring -//paddedPenceNumberString.substring value is found by starting from the first index WITH LENGTH 3 and ending with paddedPenceNumberString.length subtracted by the operator 2 - -// IN THIS LINE const pence = paddedPenceNumberString -const pence = paddedPenceNumberString - .substring(paddedPenceNumberString.length - 2) - .padEnd(2, "0"); - -console.log(`£${pounds}.${pence}`); -// we initialise a string variable and assign its value to be the paddedPenceNumberString variable with the value from using the substring method -// the substring method is calculated by using the length property or the value of paddedPenceNumberString subtracting it by 2 using operator - -// than using the method .padEnd to specify that if the length is not two add the value 0 -// last we ask the console to print the values in pounds and pence \ No newline at end of file