Skip to content
Open
Show file tree
Hide file tree
Changes from 5 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
//Line 3 taking the current value to count, then make the count to new value
17 changes: 17 additions & 0 deletions Sprint-2/1-key-errors/0.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,20 @@ function capitalise(str) {

// =============> write your explanation here
// =============> write your new code here

///The error is :

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

//str is already a parameter of the function.
//Doing let str = ... is like giving it a new name in the same place, which JavaScript does not allow.
//we can just use the existing str instead of declaring it again.

function capitalise(str) {

// make the first letter uppercase

str = str[0].toUpperCase() + str.slice(1);

return str;
}
26 changes: 24 additions & 2 deletions Sprint-2/1-key-errors/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,34 @@ function convertToPercentage(decimalNumber) {
const decimalNumber = 0.5;
const percentage = `${decimalNumber * 100}%`;

return percentage;
return percentage;=
}

console.log(decimalNumber);

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

Answer:

The number (0.5) goes into the function — that’s our decimalNumber.

We use that decimalNumber to make a percent.

We don’t write const decimalNumber again because we already have it.

We return the answer (like "50%").

Then we call the function with 0.5 and print what it gives back.

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

function convertToPercentage(decimalNumber) {

const percentage = `${decimalNumber * 100}%`;

return percentage;

}

console.log(convertToPercentage(0.5));

20 changes: 19 additions & 1 deletion Sprint-2/1-key-errors/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,33 @@
// =============> write your prediction of the error here

function square(3) {

return num * num;
}

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

SyntaxError: Unexpected number


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

the function takes the number we give it (3) and times it by itself.

so 3 * 3 = 9.

it works now cuz we used num instead of a number in the ()


// Finally, correct the code to fix the problem

// =============> write your new code here

function square(num){

return num * num
}

console.log(square(3))



12 changes: 12 additions & 0 deletions Sprint-2/2-mandatory-debug/0.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,17 @@ console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);

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

the function just prints the answer, it dont return it.

so when we try to use it inside the message it shows undefined.

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

13 changes: 13 additions & 0 deletions Sprint-2/2-mandatory-debug/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,18 @@ function sum(a, b) {
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);

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

the code dont work cuz the return stops the code before it adds the numbers.

so js never does a + b, that’s why it show undefined.

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

function sum(a, b){

return a + b
}

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

34 changes: 34 additions & 0 deletions Sprint-2/2-mandatory-debug/2.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
// Predict and explain first...

it will print 3 for all of them

// Predict the output of the following code:

The last digit of 42 is 3
The last digit of 105 is 3
The last digit of 806 is 3

// =============> Write your prediction here

const num = 103;

function getLastDigit() {

return num.toString().slice(-1);
}

Expand All @@ -15,9 +23,35 @@ 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

The last digit of 42 is 2

The last digit of 105 is 5

The last digit of 806 is 6

// Explain why the output is the way it is
// =============> write your explanation here

It always shows 3 cuz the function just uses the num at the top (103).

It ignores the numbers we put in () like 42, 105, 806.

We need to let the function take a number as input.

// Finally, correct the code to fix the problem

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)})

// =============> write your new code here

// This program should tell the user the last digit of each number.
Expand Down
16 changes: 14 additions & 2 deletions Sprint-2/3-mandatory-implement/1-bmi.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@
// Then when we call this function with the weight and height
// It should return their Body Mass Index to 1 decimal place

function calculateBMI(weight, height) {
function calculateBmi(weight,height) {
// return the BMI of someone based off their weight and height
}
}


function calculateBMI (weight,height) {

let bmi = weight / (height*height)

return bmi.toFixed(1)

}
Comment on lines 22 to 28
Copy link
Contributor

Choose a reason for hiding this comment

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

What type of value do you expect the function to return? A number or a string?
Does your function return the type of value you expect?


console.log(calculateBMI(70,1.73))

15 changes: 15 additions & 0 deletions Sprint-2/3-mandatory-implement/2-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,18 @@
// 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 that turns text into UPPER_SNAKE_CASE

function makeUpperSnake(text) {

let newText =text.replace(/ /g,'_');

newText = newText.toUpperCase();

return newText;

}
console.log(makeUpperSnake("hello there"));
console.log(makeUpperSnake("lord of the rings"));


25 changes: 25 additions & 0 deletions Sprint-2/3-mandatory-implement/3-to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,28 @@
// 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) {

let numberStr =penceString.substring(0,penceString.length -1);

numberStr = numberStr.padStart(3,"0");

let pounds = numberStr.substring(0, numberStr.length -2);

let pence = numberStr.substring(numberStr.length -2).padEnd(2,"0");

return "£" +pounds + "." +pence;
}

console.log(toPounds("399p"));
console.log(toPounds("50p"));
console.log(toPounds("5p"));
console.log(toPounds("1200p"));




59 changes: 58 additions & 1 deletion Sprint-2/4-mandatory-interpret/time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,73 @@ function formatTimeDisplay(seconds) {
// a) When formatTimeDisplay is called how many times will pad be called?
// =============> write your answer here

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

return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`;

pad is called three times: for totalHours, remainingMinutes, and remainingSeconds.

So no matter what input we give to formatTimeDisplay, pad will always be called 3 times.

// 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?
// =============> write your answer here

Answer;

The first call is pad(totalHours).

const totalHours = (totalMinutes - remainingMinutes) / 60;

The value assigned to num when pad is called for the first time is 0.
Consequently, pad(0) will return '00', which ensures that the hour is formatted correctly in the final output string


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

Answer; 1

return num.toString().padStart(2, "0");

num = 1

num.toString() = "1"

"1".padStart(2, "0") = "01"

If you call pad(0), the return value will be '00'.

If you call pad(1), the return value will be '01'.

If you call pad(5), the return value will be '05'.

If you call pad(10), the return value will be '10'



// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer
// =============> write your answer here
Answer; 1

The last call is pad(remainingSeconds).

When you call format_time_display(61):

The calculations result in:

total_hours = 0
remaining_minutes = 1
remaining_seconds = 1


// e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer
// =============> write your answer here
Answwer; 01


Third Call: pad(remaining_seconds) (where remaining_seconds = 1)

Value of num for the last call: 1

Return value: '01'
26 changes: 20 additions & 6 deletions Sprint-2/5-stretch-extend/format-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,36 @@
// Your task is to write tests for as many different groups of input data or edge cases as you can, and fix any bugs you find.

function formatAs12HourClock(time) {
const hours = Number(time.slice(0, 2));
// Expect time in "HH:MM" format
let hours = Number(time.slice(0, 2));
let mins = time.slice(3);
Copy link
Contributor

Choose a reason for hiding this comment

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

When a variable is not going to be re-assigned a value, it is best practices to declare it using const instead of let (to convey the message that it is a constant and also to prevent it from being accidently reassigned a value).

Copy link
Author

@Shayida999 Shayida999 Oct 25, 2025

Choose a reason for hiding this comment

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

Thanks CJ i fixed both, and reverted sprint 1.


if (hours === 0) {
return `12:${mins} am`;
}

if (hours === 12) {
return `12:${mins} pm`;
}

if (hours > 12) {
return `${hours - 12}:00 pm`;
let newHr = hours - 12;
// pad single digits like 1:00 -> 01:00
return `${String(newHr).padStart(2, "0")}:${mins} pm`;
}

return `${time} am`;
}

const currentOutput = formatAs12HourClock("08:00");
const targetOutput = "08:00 am";
let currentOutput = formatAs12HourClock("08:00");
let targetOutput = "08:00 am";
console.assert(
currentOutput === targetOutput,
`current output: ${currentOutput}, target output: ${targetOutput}`
);

const currentOutput2 = formatAs12HourClock("23:00");
const targetOutput2 = "11:00 pm";
let currentOutput2 = formatAs12HourClock("23:00");
let targetOutput2 = "11:00 pm";
console.assert(
currentOutput2 === targetOutput2,
`current output: ${currentOutput2}, target output: ${targetOutput2}`
Expand Down
Loading