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
af8a542
Answering the first task of sprint 1
HANISADAH Oct 18, 2025
e4c2e57
creating the dir and ext variables
HANISADAH Oct 18, 2025
b21591e
creating a variable
HANISADAH Oct 18, 2025
4102ecb
Updating the answer
HANISADAH Oct 23, 2025
8f90b4f
Modifying the answer
HANISADAH Oct 23, 2025
1da375f
Answering th task 1.js
HANISADAH Oct 23, 2025
beda7c4
Answering th task 1.js
HANISADAH Oct 23, 2025
e7f48d3
Answering 2.js
HANISADAH Oct 23, 2025
a661310
Answering 3.js
HANISADAH Oct 23, 2025
f4e13bc
Solving the code issue
HANISADAH Oct 23, 2025
b6b4ffc
Answering the questions
HANISADAH Oct 24, 2025
2478f22
answering the task questions
HANISADAH Oct 24, 2025
8beb07d
Answering 3-to-pounds.js
HANISADAH Oct 25, 2025
f070a00
Answering the task
HANISADAH Oct 31, 2025
ad0f006
Answering the task
HANISADAH Oct 31, 2025
e082897
fixing the error to add a comment slashes
HANISADAH Oct 31, 2025
85bcc9b
Answering the task
HANISADAH Oct 31, 2025
491f9b8
Answering the task
HANISADAH Oct 31, 2025
c5a8edb
Answering the task
HANISADAH Oct 31, 2025
b0547d6
Answering the task
HANISADAH Oct 31, 2025
9b194a5
Answering the task
HANISADAH Nov 1, 2025
75b0d32
Change to upper snake case
HANISADAH Nov 1, 2025
6b1aed0
Answering the task
HANISADAH Nov 1, 2025
883efa2
Answering the task
HANISADAH Nov 1, 2025
4ca75b9
Answering the task
HANISADAH Nov 1, 2025
e4ba658
Merge branch 'CodeYourFuture:main' into coursework/sprint-1
HANISADAH Nov 1, 2025
c57d664
restore sprint-2 from origin/main
HANISADAH Nov 8, 2025
9bf4964
deleted number-game-errors.html
HANISADAH Nov 8, 2025
d868527
updated answers for 1-count.js and 3-path.js
HANISADAH Nov 8, 2025
9b9dc8e
answering the task
HANISADAH Nov 8, 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
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
// line 3 is an assignment which returns the incurmented value of count after adding 1 to it.
Copy link
Contributor

Choose a reason for hiding this comment

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

I was referring to the operation that increase the value of a variable by 1. For example, count = count + 1.
Can you look up the name of such operation?

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 @@ -2,10 +2,14 @@ let firstName = "Creola";
let middleName = "Katherine";
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[0]}${middleName[0]}${lastName[0]}`;

console.log(initials)

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

19 changes: 10 additions & 9 deletions Sprint-1/1-key-exercises/3-paths.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
// 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.)


// 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}`);
const base = filePath.slice(lastSlashIndex + 1); // file.txt
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
// Create a variable to store the dir part of the filePath variable.
// Create a variable to store the ext part of the variable.

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

console.log (dir, ext)
// https://www.google.com/search?q=slice+mdn
12 changes: 12 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,15 @@ 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

//num represents the results of equations at the right side of operator =

//step-1---> Math.random() generates a random decimal.
//step-2---> (maximum - minimum + 1) evaluates to 100.
//step-3---> Math.random() is multiplied by (maximum - minimum + 1) which is 100, resulting in a random decimal between 0 and 100.
Copy link
Contributor

Choose a reason for hiding this comment

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

Phrases like "a number between X and Y" are not precise enough in a program specification, because they do not clearly state whether the endpoints X and Y are included.

We can also use the concise and precise interval notation to describe a range of values.

  • [, ] => inclusion
  • (, ) => exclusion

For example, we can describe a number, -5 < x <= 10, as "x is a number in (-5, 10]".

Can you use this notation to describe the return value of Math.random() (step-1) and the value produced in step-3?

//step-4---> the result of Step-3 is round by the method Math.floor.
//step-5---> minimum is added to the result of step-4.
//Therefore, num represents random numbers generated between minimum 1 and maximum 100, as we run the code several times
//generates new numbers.

console.log(num);
4 changes: 2 additions & 2 deletions Sprint-1/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?
5 changes: 4 additions & 1 deletion Sprint-1/2-mandatory-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// trying to create an age variable and then reassign the value by 1

const age = 33;
// in this case, we will need to replace the const keyword with let keyword as const vasriable refuses to be reassigned.
let age = 33;
age = age + 1;

console.log(age);
3 changes: 2 additions & 1 deletion Sprint-1/2-mandatory-errors/2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// 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}`);
// we need to declare the variable cityOfBirth first then we can print it out.
const cityOfBirth = "Bolton";
console.log(`I was born in ${cityOfBirth}`);
8 changes: 7 additions & 1 deletion Sprint-1/2-mandatory-errors/3.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
const cardNumber = 4533787178994213;
const last4Digits = cardNumber.slice(-4);
const last4Digits = cardNumber.toString().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

// it seems that the code is not working because the cardNumber variable is not defined as a string.
// my prediction is true.

//we need to add string to the variable cardNumber variable before using the slice method then to print the code out.
16 changes: 15 additions & 1 deletion Sprint-1/2-mandatory-errors/4.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
const 12HourClockTime = "20:53";
const 24hourClockTime = "08:53";
const 24hourClockTime = "08:53";

// we have to convert the identifiers of the variables to valid ones by removing the 12 and 24 digits and to put them in camel case format.
const twelveHourClockTime = "20:53";
const twentyFourHourClockTime = "08:53";

console.log(twelveHourClockTime);
console.log(twentyFourHourClockTime);

// The twelveHourClockTime and twentyFourHourClockTime variables should store the respective time formats
// 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 variable names to valid identifiers in order to get the correct value
9 changes: 5 additions & 4 deletions Sprint-1/3-mandatory-interpret/1-percentage-change.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ 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

// five fuction calls, in line 4, number(), and replaceAll(). in line 5, number() and replaceAll(), in line 8, console.log().
// 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?

//in line 5, a syntax error because of the missing comma inside the replaceAll method parentheses. we can fix this problem by adding the missing comma.
// c) Identify all the lines that are variable reassignment statements

// in line 4 carPrice variable is reassigned and in line 5 priceAfterONeYear as well.
// d) Identify all the lines that are variable declarations

// four variable declarations in line 1 carPrice variable is declared, in line 2 priceAfterOneYear variable is declared, in line 7 priceDifference variable is declared, and in line 8 percentageChange variable is declared.
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
// the purpose of this expression number(carPrice.replaceAll(",","")) is to change a string value that contains commas into a number value by removing the commas first using the replaceAll method and then converting the resulting string into a number using the Number function.
11 changes: 6 additions & 5 deletions Sprint-1/3-mandatory-interpret/2-time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ 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?

// six variable declarations: movieLength, remainingSeconds, totalMinutes, remainingMinutes, totalHours, result.
// b) How many function calls are there?

// only one fuction call: console.log() 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

// the expression movieLength % 60 is using the modulus operator (%) to find the remainder when movieLength is divided by 60.
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?

// the expression assigned to totalMinutes is calculating the total number of minutes in the movie by subtracting the remaining seconds from the total movie length in seconds and then dividing the result by 60 to convert it to minutes.
// e) What do you think the variable result represents? Can you think of a better name for this variable?

// the variable result represents the formatted string of the movie length in hours, minutes, and seconds. a better name for this variable could be formattedMovieLength or movieDurationFormatted.
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
// yes, this code will work for all values of movieLength as long as it is a non-negative integer representing the length of the movie in seconds. the code correctly calculates the hours, minutes, and seconds for any given length of time in seconds.
10 changes: 10 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,13 @@ console.log(`£${pounds}.${pence}`);

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

// to begin we can start with
//1- const penceSring= "399p": initialises a string variable with the value "399p"
//2- const penceStringWithoutTrailingP= a string value "399" is reassigned to penceStringWithoutTrailingP by removing the last character "p" from penceString using the substring method
//3- const paddedPenceNumberString= declared new variable, padStart ensure any argument passed is at least 3 characters long by adding leading zeros if necessary
//4- line 9 a new variable pence is declared and its value comes from the padded string by removing the last two characters which represent the pence.
//5- line 14 const pence= declared variable and the variable is the result after extracting the last two characters from paddedPenceNumberString using substring method and padEnd method is used to ensure that the pence value is always two digits long by adding trailing zeros if necessary
// from the pence string and pads it to two characters to have two digits number.
//6- line 18: console.log (`£${pounds}.${pence}`): returns money amount combing pounds and pence along with the £ symbol
//eg. £3.99