Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
eac1a1b
declaraing the variable 'result' in capitalise function
djebsoft Feb 28, 2026
0a7da43
Fix duplicate variable declaration and assigning in convertToPercenta…
djebsoft Feb 28, 2026
45b6a43
Fix square function parameter
djebsoft Feb 28, 2026
b594c90
Fix multiply function to return and log result
djebsoft Feb 28, 2026
7fbd07f
Fix sum function to return correct value
djebsoft Feb 28, 2026
54e11ce
Fix getLastDigit function to return correct last digit
djebsoft Feb 28, 2026
97bdb37
Fixing typo
djebsoft Feb 28, 2026
9dfa312
Implement BMI calculation in calculateBMI function
djebsoft Feb 28, 2026
5fb3b93
Update comments with answers in time-format.js
djebsoft Mar 1, 2026
b745976
turn the to-pounds program into a reusable block of code
djebsoft Mar 1, 2026
6dcd3ad
Implement upperSnakeCase function
djebsoft Mar 1, 2026
98c6c44
formatting using prettier
djebsoft Mar 7, 2026
49c0e77
formatting using prettier
djebsoft Mar 7, 2026
f46495a
formatting using prettier
djebsoft Mar 7, 2026
3a4cd9c
formatting using prettier
djebsoft Mar 7, 2026
0187c34
formatting using prettier
djebsoft Mar 7, 2026
d824908
formatting using prettier
djebsoft Mar 7, 2026
e3e2a6e
formatting using prettier
djebsoft Mar 7, 2026
d979e47
formatting using prettier
djebsoft Mar 7, 2026
074eddb
formatting using prettier
djebsoft Mar 7, 2026
614b5fc
formatting using prettier
djebsoft Mar 7, 2026
4e87db6
formatting using prettier
djebsoft Mar 7, 2026
ecbbbef
formatting using prettier
djebsoft Mar 7, 2026
69ae220
formatting using prettier
djebsoft Mar 7, 2026
0f84719
deleted the console.log statement from the function and added a retur…
djebsoft Mar 12, 2026
3adc57d
fixed the statement of the value returned & converted the output to a…
djebsoft Mar 12, 2026
1393ad5
fixed the function to return the coverted value
djebsoft Mar 12, 2026
132b50e
Fix return statement in calculateBMI function
djebsoft Mar 12, 2026
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
11 changes: 8 additions & 3 deletions Sprint-2/1-key-errors/0.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Predict and explain first...
// =============> write your prediction here
// =============> the function is not going to work because a variable is declared twice (str)

// call the function capitalise with a string input
// interpret the error message and figure out why an error is occurring
Expand All @@ -9,5 +9,10 @@ function capitalise(str) {
return str;
}

// =============> write your explanation here
// =============> write your new code here
// =============> the error message 'Identifier 'str' has already been declared', diplays because the toUpperCase function does not change the value of the varible declared
// but it creates a new one.
// =============> my new code:
function capitalise(str) {
let result = `${str[0].toUpperCase()}${str.slice(1)}`;
return resault;
}
13 changes: 10 additions & 3 deletions Sprint-2/1-key-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Predict and explain first...

// Why will an error occur when this program runs?
// =============> write your prediction here
// =============> because first: the variable decimalNumber is declared twice
// second: the parameter decimalNumber is assigned to a value inside the function

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

Expand All @@ -14,7 +15,13 @@ function convertToPercentage(decimalNumber) {

console.log(decimalNumber);

// =============> write your explanation here
// =============> Identifier 'decimalNumber' has already been declared is the error msg thrown by the code

// Finally, correct the code to fix the problem
// =============> write your new code here
// =============>
function convertToPercentage(decimalNumber) {
// const decimalNumber = 0.5; this line must be deleted
const percentage = `${decimalNumber * 100}%`;

return percentage;
}
14 changes: 8 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,20 @@

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

// =============> write your prediction of the error here
// =============> identifier not declared (unknown)

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

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

// =============> explain this error message here
// =============> the parameter shouldn't be given an argument in the function definition

// Finally, correct the code to fix the problem

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


// =============> my new code
function square(num) {
return num * num;
}
console.log(square(3));
13 changes: 9 additions & 4 deletions Sprint-2/2-mandatory-debug/0.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
// Predict and explain first...

// =============> write your prediction here
// =============> the function when called will throw an error

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

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

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

// =============> the function multiply has no return statement
// when we call the function multiply(10, 32) it will throw this message: The result of multiplying 10 and 32 is undefined
// Finally, correct the code to fix the problem
// =============> write your new code here
// =============>
function multiply(a, b) {
return a * b; // we change the console.log statement with the return statement
}

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

function sum(a, b) {
return;
Expand All @@ -8,6 +8,12 @@ function sum(a, b) {

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

// =============> write your explanation here
// =============> the function sum returns Nul because it's straight followed by semicolon thate ends the statement
// also the statement a + b is in new line
// Finally, correct the code to fix the problem
// =============> write your new code here
// =============> my new code
function sum(a, b) {
return a + b;
}

console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
19 changes: 16 additions & 3 deletions Sprint-2/2-mandatory-debug/2.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// Predict and explain first...

// Predict the output of the following code:
// =============> Write your prediction here
// =============>
// The last digit of 42 is 3
// The last digit of 105 is 3
// The last digit of 806 is 3

const num = 103;

Expand All @@ -14,11 +17,21 @@ 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
// =============> the variable num is assigned to the value 103 in the global scope and not assigned to any value in the function scope
// Finally, correct the code to fix the problem
// =============> write your new code here
function getLastDigit(num) {
// we add the identifier num as parameter to the 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)}`);

// This program should tell the user the last digit of each number.
// Explain why getLastDigit is not working properly - correct the problem
7 changes: 4 additions & 3 deletions Sprint-2/3-mandatory-implement/1-bmi.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// The BMI calculation divides an adult's weight in kilograms (kg) by their height in metres (m) squared.

// For example, if you weigh 70kg (around 11 stone) and are 1.73m (around 5 feet 8 inches) tall, you work out your BMI by:

//
// squaring your height: 1.73 x 1.73 = 2.99
// dividing 70 by 2.99 = 23.41
// Your result will be displayed to 1 decimal place, for example 23.4.
Expand All @@ -15,5 +15,6 @@
// It should return their Body Mass Index to 1 decimal place

function calculateBMI(weight, height) {
// return the BMI of someone based off their weight and height
}
return Number((weight / (height * height)).toFixed(1)); // return the BMI of someone based off their weight and height
}
console.log(calculateBMI(90, 1.77)); // when calling this function with given someone's weight and height
6 changes: 6 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,9 @@
// 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(wordsSet) {
let wsSnakeCase = wordsSet.replaceAll(" ", "_");
let wsupperSnakeCase = wsSnakeCase.toUpperCase();
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about this version:wsUpperSnakeCase? (No change needed)

Copy link
Author

@djebsoft djebsoft Mar 12, 2026

Choose a reason for hiding this comment

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

I think it could be shortened and embeded in the previous line

return wsupperSnakeCase;
}
upperSnakeCase("i do not know"); // evaluates to: "I_DO_NOT_KNOW"
21 changes: 21 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,24 @@
// 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 console.log(`£${pounds}.${pence}`);
}
toPounds("399p"); // £3.99
toPounds("1095p"); // £10.95
18 changes: 14 additions & 4 deletions Sprint-2/4-mandatory-interpret/time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,27 @@ function formatTimeDisplay(seconds) {

// a) When formatTimeDisplay is called how many times will pad be called?
// =============> write your answer here
// =============> pad will 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
// =============> the value assigned to num is 0

// c) What is the return value of pad is called for the first time?
// =============> write your answer here
// =============> the return value of pad is called for the first time is "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
// =============> the value assigned to num is 1
// because the last time pad is called for the remainingSeconds holding the value 1
// return pad(remainingSeconds)
// function pad(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
// =============> the return value of pad is called for the last time is "01"
// because the argument passed to the pad parameter is the value of the remainingSeconds wich is 1
// function pad(1){
// return 1.toString().padStart(2, "0");
// return "1".pad(2,"0");
// return "01"
//}
Loading