Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion Sprint-1/1-key-exercises/1-count.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +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
// 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?

10 changes: 5 additions & 5 deletions Sprint-1/1-key-exercises/3-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

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.

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

console.log (dir)
console.log (dir, ext)
// https://www.google.com/search?q=slice+mdn
21 changes: 9 additions & 12 deletions Sprint-1/1-key-exercises/4-random.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,14 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
// 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);
18 changes: 4 additions & 14 deletions Sprint-2/1-key-errors/0.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
// Predict and explain first...
// =============> 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.
// =============> write your prediction here

// 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) {
str = `${str[0].toUpperCase()}${str.slice(1)}`;
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
return str;
}
console.log (capitalise ('hello'));


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

// Why will an error occur when this program runs?
// =============> 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.
// =============> write your prediction here

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

// 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() {
function convertToPercentage(decimalNumber) {
const decimalNumber = 0.5;
const percentage = `${decimalNumber * 100}%`;

return percentage;
}

console.log(convertToPercentage());
console.log(decimalNumber);

// =============> write your explanation here

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

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

// =============> 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.
// =============> write your prediction of the error here

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

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

// =============> 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: 6 additions & 12 deletions Sprint-2/2-mandatory-debug/0.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
// Predict and explain first...

// =============> 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.
// =============> write your prediction here

//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)}`);

// =============> 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.
// =============> write your explanation here

// 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...
// =============> SyntaxError will occur due to putting a semicolon after return.
// =============> write your prediction here

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

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

// =============> unlike the expectation that the code runs without error as 'the sum of 10 and 32 is undefined'.
// =============> write your explanation here
// 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: 11 additions & 21 deletions Sprint-2/2-mandatory-debug/2.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,24 @@
// Predict and explain first...

// Predict the output of the following code:
// =============> 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.
// =============> Write your prediction here

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

//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)}`);

// Now run the code and compare the output to your prediction
// =============> 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) {
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)}`);

// 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
// Finally, correct the code to fix the problem
// =============> write your new code here

// 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: 1 addition & 4 deletions Sprint-2/3-mandatory-implement/1-bmi.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,5 @@
// 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));
}
12 changes: 0 additions & 12 deletions Sprint-2/3-mandatory-implement/2-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,3 @@
// You will need to come up with an appropriate name for the function
// Use the MDN string documentation to help you find a solution
// This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase

function capSnakeCase(str) {
const upper = str.toUpperCase();
const snake = upper.replace(/ /g, "_");
return snake;
}
console.log(capSnakeCase("lord of the rings"));

// step 1: get a string input
//step 2: change the upper case
//step 3: replace spaces with underscores
// step 4: return capSnakeCase
12 changes: 0 additions & 12 deletions Sprint-2/3-mandatory-implement/3-to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,3 @@
// You will need to declare a function called toPounds with an appropriately named parameter.

// You should call this function a number of times to check it works for different inputs

function toPounds (penceString){
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");

return `£${pounds}.${pence}`;
}
console.log(toPounds("399p"))
console.log(toPounds("5p"))
console.log(toPounds("5678p"))
12 changes: 6 additions & 6 deletions Sprint-2/4-mandatory-interpret/time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@ function formatTimeDisplay(seconds) {

return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`;
}
console.log(formatTimeDisplay(61));

// You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit
// to help you answer these questions

// Questions

// a) When formatTimeDisplay is called how many times will pad be called?
// =============> It will be called 3 times.
// =============> write your answer here

// Call formatTimeDisplay with an input of 61, now answer the following:

// b) What is the value assigned to num when pad is called for the first time?
// =============> 0
// =============> write your answer here

// c) What is the return value of pad is called for the first time?
// =============> 00
// =============> write your answer here

// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer
// =============> The leftover second is assigned to num as remainingSEconds 61%60
// =============> write your answer here

// e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer
// =============> 01 the remainingSeconds from passed from pad to num is changed to string and padded as 01
// =============> write your answer here
55 changes: 0 additions & 55 deletions Sprint-2/5-stretch-extend/format-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,58 +23,3 @@ console.assert(
currentOutput2 === targetOutput2,
`current output: ${currentOutput2}, target output: ${targetOutput2}`
);

const currentOutput3 = formatAs12HourClock("00:00");
const targetOutput3 = "12:00 am";
console.assert(
currentOutput3 === targetOutput3,
`current output: ${currentOutput3}, target output: ${targetOutput3}`
);

const currentOutput4 = formatAs12HourClock("12:00");
const targetOutput4 = "12:00 pm";
console.assert(
currentOutput4 === targetOutput4,
`current output: ${currentOutput4}, target output: ${targetOutput4}`
);

const currentOutput5 = formatAs12HourClock("13:00");
const targetOutput5 = "1:00 pm";
console.assert(
currentOutput5 === targetOutput5,
`current output: ${currentOutput5}, target output: ${targetOutput5}`
);

const currentOutput7 = formatAs12HourClock("25:00");
const targetOutput7 = "01:00 am";
console.assert(
currentOutput7 === targetOutput7,
`current output: ${currentOutput7}, target output: ${targetOutput7}`
);

// modified code:

function formatAs12HourClock(time) {
let hours = Number(time.slice(0, 2));
const minutes = time.slice(3);

let suffix;
if (hours >= 12) {
suffix = "pm";

} else {
suffix = "am";
}
hours = hours % 12 || 12; // Convert 0 to 12, 13 to 1
const formattedHours = hours.toString().padStart(2, '0');

return `${formattedHours}:${minutes} ${suffix}`;
}

const currentOutput6 = formatAs12HourClock("23:00");
const targetOutput6 = "11:00 pm";
console.assert(
currentOutput6 === targetOutput6,
`current output: ${currentOutput6}, target output: ${targetOutput6}`
);

Empty file removed number-game-errors.html
Empty file.