Skip to content

ZA | MAY-2025 | OBERT TILIMANDZI | MODULE-STRUCTURING AND TESTING DATA | COURSEWORK SPRINT 1 #591

New issue

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

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

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 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,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
// Answer: "count + 1" is a value being assigned to the variable count and "=" is the assignement operator used to assign values to a variable
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

28 changes: 22 additions & 6 deletions Sprint-1/1-key-exercises/3-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,30 @@
// (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";

// Find the last slash and we can seperate the base from "dir"
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
// Find the last dot
const lastDot = base.lastIndexOf(".");
// console.log(`The base part of ${filePath} is ${base}`);

// Ectract everything before the base
const dir = filePath.slice(0, lastSlashIndex);
// Extract the txt extention from the dot
const ext = base.slice(lastDot);




const dir = ;
const ext = ;

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





// Create a variable to store the dir part of the filePath variable
// Create a variable to store the ext part of the variable
console.log(`The base part of ${filePath} is ${base}`);
// Moved to bottom its confusing me
8 changes: 8 additions & 0 deletions Sprint-1/1-key-exercises/4-random.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@ 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

// Answer: Inermost brackets first (maximum - minimum + 1) this is calcuating the range
// Math.random generated a number between 0 and 1 but wont get to 1
// Math.random * 100 moved the comma by 2 decimal places
// Math.floor wii remove decimal parts of the number
// + minimum will add 1

console.log(num);
6 changes: 5 additions & 1 deletion Sprint-1/2-mandatory-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
// trying to create an age variable and then reassign the value by 1

const age = 33;
let age = 33;
age = age + 1;
age = 1;


// Will remove the constant varible and use the let keyword
5 changes: 4 additions & 1 deletion Sprint-1/2-mandatory-errors/2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// 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}`);


// The variable was at the bottom so we could not access it, so it has to be hoisted at the top
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.slice(-4);
const last4Digits = String(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
// Answer: Missing console.log
// Then run the code and see what error it gives.
// Error:we had TypeError: cardNumber.slice is not a function
// Consider: Why does it give this error? Is this what I predicted? If not, what's different?
// "cardNumber.slice" must declared as a function, this is not what i thought, the difference is that the code is incomplete and so will add a function
// Then try updating the expression last4Digits is assigned to, in order to get the correct value


// After some research i found out that ".slice()" only works on strings so we have to convert the numbers into a string first
// Also learned abour method chaining
6 changes: 4 additions & 2 deletions Sprint-1/2-mandatory-errors/4.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
const 12HourClockTime = "20:53";
const 24hourClockTime = "08:53";
const HourClockTime12 = "20:53";
const hourClockTime24 = "08:53";

// You cannot name a variable starting witha number
7 changes: 6 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,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
// Anwer: The function is called 4 times in the code line 7 and 8 then we have the built-in functions line 4 and 5

// 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?
// Answer: The error is coming from line 5 a comma is missing between the quotes '(priceAfterOneYear.replaceAll("," ""))'

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

// d) Identify all the lines that are variable declarations
// Answer: Line 1, 2, 7 and 8

// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
// Answer: It removing all the commas and also converting the values to a number
8 changes: 7 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 = 81034; // length of movie in seconds

const remainingSeconds = movieLength % 60;
const totalMinutes = (movieLength - remainingSeconds) / 60;
Expand All @@ -12,14 +12,20 @@ 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?
// Answer: There are 6

// b) How many function calls are there?
// Answer: There ise one "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
// Answer: This devides values and gives us the remainder

// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
// Answer: It subtracts remaining seconds from movie length then devides that by 60

// e) What do you think the variable result represents? Can you think of a better name for this variable?
// Answer: This will display the movie length formatted in hours, minutes and seconds, it can be named totalTime

// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
// Answer: Yes it works with all values, this can be because there are template litterals in the result variable
13 changes: 13 additions & 0 deletions Sprint-1/3-mandatory-interpret/3-to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,16 @@ console.log(`£${pounds}.${pence}`);

// To begin, we can start with
// 1. const penceString = "399p": initialises a string variable with the value "399p"

// 2. penceStringWithoutTrailingP the last "p" from line 1 is removed
// substring() method will select a charactor from index 0 to -1, and return the new string "-1 is the last charactor" then we get "399"

// 3. paddedPenceNumberString this is assingned to the variable penceStringWithoutTrailingP where a charactor is added to the beggining of the string by the method padStart
// 3 will add 2 zeros to the begining of the string, we have padStart(3, "0") and we already have three charactor
// if it was padStart(4, "0") then the result was "0399"

// 4. pounds will take the paddedPenceNumberString, select all the charactors exept the last two

// 5. pence selects the values in paddedPenceNumberString, then makes sure we have the last we have two digits at the end

// console will print the output value in pounds
1 change: 1 addition & 0 deletions Sprint-1/Module-Structuring-and-Testing-Data
Submodule Module-Structuring-and-Testing-Data added at 9b108f
2 changes: 2 additions & 0 deletions Sprint-3/3-mandatory-practice/implement/repeat.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
function repeat() {
const countString = [0];
for(i )
return "hellohellohello";
}

Expand Down