Skip to content
Open
Show file tree
Hide file tree
Changes from 26 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 returns the incurmented value of count after adding 1 to it and assigns this new value back to count
Copy link
Contributor

Choose a reason for hiding this comment

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

Operation like count = count + 1 is very common in programming, and there is a programming term describing such operation.

Can you find out what one-word programming term describes the operation on line 3?

Copy link
Author

Choose a reason for hiding this comment

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

I believe the term is assignment. It is the process of giving a value to a variable using an assignment operator.

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 increases the value of a variable by certain amount.

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

17 changes: 9 additions & 8 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}`);
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(lastSlashIndex+1)
const ext = filePath.slice(lastDotIndexOf(".") +1);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this script works as expected. Can you test it and fix the bug?


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














Copy link
Contributor

Choose a reason for hiding this comment

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

This exercise expects you to explain how the expression on line 4 works.

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
18 changes: 14 additions & 4 deletions Sprint-2/1-key-errors/0.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
// Predict and explain first...
// =============> write your prediction here
// =============> I predict that we will not need to write let in line 8 as str is already declared
// as an argument within the function captialise.

// call the function capitalise with a string input
// interpret the error message and figure out why an error is occurring

// function capitalise (str) {
// let str = `${str[0].toUpperCase()}${str.slice(1)}`;
// return str;
// }

// capitalise ('hello');
//==============> A syntaxError occurred as 'str' is being cleared.


function capitalise(str) {
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
str = `${str[0].toUpperCase()}${str.slice(1)}`;
return str;
}
console.log (capitalise ('hello'));


// =============> write your explanation here
// =============> write your new code here
26 changes: 19 additions & 7 deletions Sprint-2/1-key-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
// Predict and explain first...

// Why will an error occur when this program runs?
// =============> write your prediction here
// =============> I believe that the function convertToPercentage is not mentioned in the console.log statement.
// Declaring the const decimalNumber is unnecessary as it is already declared as a parameter within the function convertToPercentage.

// Try playing computer with the example to work out what is going on

function convertToPercentage(decimalNumber) {
// function convertToPercentage(decimalNumber) {
// const decimalNumber = 0.5;
// const percentage = `${decimalNumber * 100}%`;

// return percentage;
//}

// console.log(decimalNumber);

// =============> A syntaxError occurred saying decimalNumber is already declared.

// Finally, correct the code to fix the problem
// =============> write your new code here

function convertToPercentage() {
const decimalNumber = 0.5;
const percentage = `${decimalNumber * 100}%`;

return percentage;
}

console.log(decimalNumber);

// =============> write your explanation here
console.log(convertToPercentage());

// Finally, correct the code to fix the problem
// =============> write your new code here
// the new code runs without error and outputs "50%"
19 changes: 13 additions & 6 deletions Sprint-2/1-key-errors/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,25 @@

// this function should square any number but instead we're going to get an error

// =============> write your prediction of the error here
// =============> The num parameter should be mentioned inside the function square instead of the number 3.
// then it should be called as square (3) in the console.log statement.

function square(3) {
return num * num;
}
//function square(3) {
//return num * num;
//}

// =============> function square(3) syntaxError: Unexpected number.
// =============> 3 wasn't expected... instead a declaration like 'num' was expected.

// =============> write the error message here

// =============> explain this error message here

// Finally, correct the code to fix the problem

// =============> write your new code here
function square(num) {
return num * num;
}

console.log(square(3));


18 changes: 12 additions & 6 deletions Sprint-2/2-mandatory-debug/0.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
// Predict and explain first...

// =============> write your prediction here
// =============> In line 6, instead of console.log printing the result of multiply(10, 32), return a*b would be better
//because the console.log would only print a*b.

function multiply(a, b) {
console.log(a * b);
}
//function multiply(a, b) {
//console.log(a * b);
//}

console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
//console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);

// =============> write your explanation here
// =============> After running the code, we got 'the result of multiplying 10 and 32 is undefined'
// as the multiply parameters weren't considered as parameters inside the function multiply.

// Finally, correct the code to fix the problem
// =============> write your new code here
function multiply(a, b) {
return a * b;
}
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
8 changes: 4 additions & 4 deletions Sprint-2/2-mandatory-debug/1.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Predict and explain first...
// =============> write your prediction here
// =============> SyntaxError will occur due to putting a semicolon after return.

function sum(a, b) {
return;
a + b;
return a + b;
}

console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);

// =============> write your explanation here
// =============> unlike the expectation that the code runs without error as 'the sum of 10 and 32 is undefined'.
// Finally, correct the code to fix the problem
// =============> write your new code here
// we needed just to remove the semicolon after return statement and to bring up the a+b expression side by side with return.
32 changes: 21 additions & 11 deletions Sprint-2/2-mandatory-debug/2.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
// Predict and explain first...

// Predict the output of the following code:
// =============> Write your prediction here
// =============> The code will return 3 as a string first, but after calling the getLastDigit function,
// it will not return anything because every number based will be converted to string.

const num = 103;
//const num = 103;

function getLastDigit() {
return num.toString().slice(-1);
}
//function getLastDigit() {
// return num.toString().slice(-1);
//}

console.log(`The last digit of 42 is ${getLastDigit(42)}`);
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
//console.log(`The last digit of 42 is ${getLastDigit(42)}`);
//console.log(`The last digit of 105 is ${getLastDigit(105)}`);
//console.log(`The last digit of 806 is ${getLastDigit(806)}`);

// Now run the code and compare the output to your prediction
// =============> write the output here
// Explain why the output is the way it is
// =============> write your explanation here
// =============> The last digit of 42 is 3 three times.
// the prediction was close but not accurate, the case is that the parameter num needs to be
//the function instead of const num = 103.
// =============>
// Finally, correct the code to fix the problem
// =============> write your new code here

function getLastDigit(num) {
return num.toString().slice(-1);
}

console.log(`The last digit of 42 is ${getLastDigit(42)}`);
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
// This program should tell the user the last digit of each number.
// Explain why getLastDigit is not working properly - correct the problem
// parameter num needs to be with the getLastDigit function instead of const num=103.
5 changes: 4 additions & 1 deletion Sprint-2/3-mandatory-implement/1-bmi.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@
// It should return their Body Mass Index to 1 decimal place

function calculateBMI(weight, height) {
const bmi = weight / (weight*height);
return bmi.toFixed(1);
// return the BMI of someone based off their weight and height
}
}
console.log("the BMI is", calculateBMI(70, 1.73));
Loading
Loading