Skip to content
13 changes: 9 additions & 4 deletions Sprint-3/1-key-errors/0.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
// 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;
}
// function capitalise(str) {
// let str = `${str[0].toUpperCase()}${str.slice(1)}`;
// return str;
// }

// =============> write your explanation here
// The str has already been called so when its been set to the "let = str" it wont work as its already part of the function, so the name needs to change.
// =============> write your new code here
function capitalise(str) {
let capitaliseStr = `${str[0].toUpperCase()}${str.slice(1)}`;
return str;
}
24 changes: 18 additions & 6 deletions Sprint-3/1-key-errors/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,31 @@

// Why will an error occur when this program runs?
// =============> write your prediction here
// decimalNumber is part of the function so it cant be set with const decimalNumber, the name needs to be different.
// console.log(decimalNumber) causes an issue as well, decimalNumber is part of the function, it should request convertToPercentage for it to work.

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

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

return percentage;
}
// return percentage;
// }

console.log(decimalNumber);
// console.log(decimalNumber);

// =============> write your explanation here
// console.log(decimalNumber) will not work as decimalNumber is inside the function,
// and "const devimalNumber = 0.5" has already been called from teh function. You need to change the name or apply the value in the call on consol.log()


// 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));
16 changes: 12 additions & 4 deletions Sprint-3/1-key-errors/2.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@

// Predict and explain first BEFORE you run any code...

// this function should square any number but instead we're going to get an error
// the function square(3) wont work as you cant have a number value for the function.

// =============> write your prediction of the error here
// return num * num; wont work as

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

// =============> write the error message here
// SyntaxError: Unexpected number

// =============> explain this error message here
// in the () is the parameter for the function and that cannot be a number as it has to be a name, following the same rules
// that are used so it can't start with a number.

// Finally, correct the code to fix the problem

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


console.log(square(3));
17 changes: 13 additions & 4 deletions Sprint-3/2-mandatory-debug/0.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
// Predict and explain first...

// =============> write your prediction here
// syntax error as console.log(a, b) cant be part of the function.

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
// I was wrong, it is showing the answer with console.log but giving undefined for the other as the function is incomplete.

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

function multiply(a, b) {
let answer = (a * b);
return answer
}

console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
15 changes: 11 additions & 4 deletions Sprint-3/2-mandatory-debug/1.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
// Predict and explain first...
// =============> write your prediction here
// Going to show undefined

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

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

// =============> write your explanation here
// the code is not doing the sum needed of a + b as they are just split by the ; ,

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

function sum(a, b) {
return a + b;
}
33 changes: 25 additions & 8 deletions Sprint-3/2-mandatory-debug/2.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,41 @@
// Predict and explain first...

// Predict the output of the following code:
// Predict the output of the following code:
// =============> Write your prediction here
// num is made to be 103, so every .log will have the answer being 3.
// function getLasDigit() has no parameter set, so the number set

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
// The last digit of 42 is 3
// The last digit of 105 is 3
// The last digit of 806 is 3

// Explain why the output is the way it is
// =============> write your explanation here
// const num = 103 is making it that num is always 103, also function getLastDigit() has no parameter set.
// This makes it that the value from teh console.log() wont be used.

// 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
7 changes: 6 additions & 1 deletion Sprint-3/3-mandatory-implement/1-bmi.js

@JaypeeLan JaypeeLan Sep 24, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Don't hard code any value. It makes the code return the incorrect value.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Ah i see my error, I changed the 70 to weight and that fixed it.

Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,10 @@
// It should return a string of their Body Mass Index to 1 decimal place

function calculateBMI(weight, height) {
// return the BMI of someone based off their weight and height
let squaring=height * height;
return (weight / squaring).toFixed(2);

}

console.log(calculateBMI(100, 1.85));
console.log(calculateBMI(80, 1.75));
7 changes: 7 additions & 0 deletions Sprint-3/3-mandatory-implement/2-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,10 @@
// 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 upperSnakeCase(text) {
let upperCase = text.toUpperCase("");
return upperCase.replaceAll(" ", "_");
}

console.log(upperSnakeCase("Hello World"))
45 changes: 45 additions & 0 deletions Sprint-3/3-mandatory-implement/3-to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,48 @@
// 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

// const penceString = "399p";

// 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");

// console.log(`£${pounds}.${pence}`);

function poundsAndPence(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(poundsAndPence("399p"))
console.log(poundsAndPence("599p"))
console.log(poundsAndPence("1796p"))
console.log(poundsAndPence("562p"))
console.log(poundsAndPence("2p"))
// const penceString = "399p";
16 changes: 15 additions & 1 deletion Sprint-3/4-mandatory-interpret/time-format.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,52 @@
console.log("entered data")
function pad(num) {
console.log("pad has been called: Num is", num);
let numString = num.toString();
while (numString.length < 2) {
numString = "0" + numString;
}
console.log("numString: ", numString);
return numString;
}

function formatTimeDisplay(seconds) {
console.log("entered formatTimeDisplay");
const remainingSeconds = seconds % 60;
console.log("remainingSeconds: ", remainingSeconds);
const totalMinutes = (seconds - remainingSeconds) / 60;
console.log("totalMinutes: ", totalMinutes);
const remainingMinutes = totalMinutes % 60;
console.log("remainingMinutes: ", remainingMinutes);
const totalHours = (totalMinutes - remainingMinutes) / 60;
console.log("totalHours: ", totalHours);


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?
// =============> write your answer here
// Pad is being 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
// 0

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

// 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
// 1, The value given is the remainder after being used in remainingMinutes section of the code

// e) What is the return value of pad when it is called for the last time in this program? Explain your answer
// =============> write your answer here
// 01, after going through pad it ensures that there is two 00 if there is no value left, with just 1 it adds one 0 to the front of 1.
Loading