Skip to content
15 changes: 11 additions & 4 deletions Sprint-3/1-key-errors/0.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
// Predict and explain first...
// =============> write your prediction here
// =============> If the function will be called, it will print the first letter of the string
// in capital with the rest of the word in lowercase

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

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

// =============> A SyntaxError was thrown because the str was used to name both the function parameter
// and a new variable, which cannot happen in the same scope
// =============>
function capitalise(str) {
return `${str[0].toUpperCase()}${str.slice(1)}`;
}

// =============> write your explanation here
// =============> write your new code here
console.log(capitalise("mother"));
17 changes: 12 additions & 5 deletions Sprint-3/1-key-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
// Predict and explain first...
// There will be another syntax error, because the same name is used for both the parameter and the variable
// (decimalNumber)

// Why will an error occur when this program runs?
// =============> write your prediction here
// =============>
// We cannot redeclare a variable with the same name in the same scope.

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

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

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

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

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

// =============> write your prediction of the error here
// I predict it will say 'num is not defined'

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

// Instead of a parameter name, the actual value was passed, resulting in an error;
// Finally, correct the code to fix the problem

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


function square(num) {
return num * num;
}
console.log(square(6));
12 changes: 10 additions & 2 deletions Sprint-3/2-mandatory-debug/0.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Predict and explain first...

// =============> write your prediction here
// =============>
// Variables haven't been declared, so it will throw a reference error

function multiply(a, b) {
console.log(a * b);
Expand All @@ -9,6 +10,13 @@ function multiply(a, b) {
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);

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

// It printed 32 because that particular console function is inside the multiply function (local), whereas the other one
// is outside the scope and when we call the multiply function it comes up as undefined because nothing has been returned
// inside of it.
// Finally, correct the code to fix the problem
// =============> write your new code here

/* function multiply(a, b) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Your new code on lines 19 to 22 is correct. But it is inside /* */, so it never runs. The original code on lines 6 to 10 still runs. That is why the file still prints undefined.

You can check this yourself. In VS Code, right click 0.js in the file list on the left, and choose Open in Integrated Terminal. The terminal opens in the same folder as the file. Then run:

node 0.js

Please do the opposite, like in your other files: put the original code inside /* */, and take your new code out of it. Then run the command again. It should print The result of multiplying 10 and 32 is 320.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Fixed now. It prints 320. Good.

return a * b;
}
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); */
8 changes: 8 additions & 0 deletions Sprint-3/2-mandatory-debug/1.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
// Predict and explain first...
// =============> write your prediction here
// it will print the following: `The sum of 10 and 32 is undefined'

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

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

// =============> write your explanation here
// the function sum doesn't return any value. The arithmetic operation doesn't execute because it's defined after 'return'
// 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)}`);
20 changes: 18 additions & 2 deletions Sprint-3/2-mandatory-debug/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

// Predict the output of the following code:
// =============> Write your prediction here

const num = 103;
// it will not print the correct last digits
/*const num = 103;

function getLastDigit() {
return num.toString().slice(-1);
Expand All @@ -12,13 +12,29 @@ function getLastDigit() {
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

// Because the method uses the num value which is 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
// The function getLastDigit wasn't using intended parameters
4 changes: 4 additions & 0 deletions Sprint-3/3-mandatory-implement/1-bmi.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,9 @@
// It should return a string of their Body Mass Index to 1 decimal place

function calculateBMI(weight, height) {
let bmi = weight / (height * height);
return bmi.toFixed(1);

// return the BMI of someone based off their weight and height
}
console.log(`Your Bmi is ${calculateBMI(56, 1.66)}`);
9 changes: 9 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,12 @@
// 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 upperCaseMaker(str) {

@abdishakoor-dev abdishakoor-dev Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Your function works: it gives THE_SUN_IS_SHINING. Only the name needs to change.

The name upperCaseMaker tells the reader that your function only makes the letters capital. But your function makes the letters capital and replaces spaces with _. That is called upper snake case (see line 4).

JavaScript already has a method called toUpperCase, which you use on line 19. If you use that name as inspiration, and knowing what upper snake case means, what would more appropriate function name that reflects what the function is actually doing? Please rename it, and update call on line 25.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

upperSnakeCaseMaker says both jobs now. Good.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For next time: a name like toUpperSnakeCase would fit even better. It follows the same pattern as JavaScript's own toUpperCase, which you use on line 19: "to" plus what the string becomes. Other developers will recognise that pattern straight away. Your name is fine for this exercise, so no change is needed.

let upperCased = str.toUpperCase();
let symbol = "_";
let underscored = upperCased.split(" ").join(symbol);
return underscored;
}

console.log(upperCaseMaker("the sun is shining"));
20 changes: 20 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,23 @@
// 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("11000p"));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good range of inputs on line 26, from 0p to 11000p. Line 6 asks you to call the function a number of times. Please turn these into calls, like line 25, so anyone who runs the file can see the results.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good, all six inputs run now.

// results of some different inputs: 0p -> £0.00, 3p -> £0.03, 50p -> £0.50, 170p -> £1.70, 1200p -> £12.00, 11000p -> £110.00
10 changes: 5 additions & 5 deletions Sprint-3/4-mandatory-interpret/time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ function formatTimeDisplay(seconds) {
// Questions

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

// 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, because that's the actual value assigned to the num parameter

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

d) asks you to explain your answer. "because that's the actual value assigned to the num parameter" only repeats the question. Where does the 1 come from?

Your answer to e) on line 38 already says it: remainingSeconds is 1. Please add that reason to d) as well.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That's the reason. Good.


// 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", the remainingSeconds is 1, which gets padded to "01" in the return value
Loading