Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
4e992fc
In 1-Key-errors/0.js Syntax Error corrected and code run correctly
Mahtem Oct 24, 2025
be4ee28
In 1-Key-errors/1.js Syntax Error identified, corrected and new code …
Mahtem Oct 24, 2025
45af577
In 1-Key-errors/2.js, predicted what the error would be, run the code…
Mahtem Oct 24, 2025
ef668cc
In 2-Mandatory-debug/0.js, predictedwhat the code would return and mo…
Mahtem Oct 24, 2025
4ef9f59
In 2-Mandatory-debug/1js, the code has been fixed with slight modifca…
Mahtem Oct 24, 2025
b7707e3
In 2-Mandatory-debug/2.js, predicted the case explained the scenario …
Mahtem Oct 24, 2025
3ba023b
In-3-Mandatory/1-bmi.js, a code to return the BMI to 1 decimal place …
Mahtem Oct 24, 2025
3d61c7f
In-3-Mandatory-implement/2-cases.js, a code that returns capSnakecase…
Mahtem Oct 24, 2025
971777e
In -3-Mandatory-implement/3-to-pounds.js. took lines of code from spr…
Mahtem Oct 24, 2025
e9f24d4
In-4-mandatory-interpret/time-format.js execution intepration has bee…
Mahtem Oct 24, 2025
8da53ea
In-5-Strech-extended/format-time.js, tested different input groups an…
Mahtem Oct 24, 2025
4d2946e
decimalNumber has now been taken as a parameter.
Mahtem Oct 30, 2025
976687d
1-bmi.js updated a code .... return Number(bmi.toFixed(1)); to so th…
Mahtem Oct 30, 2025
2cfbda1
Updated the comment
Mahtem Oct 30, 2025
46f9c56
Edited the string "00"
Mahtem Oct 30, 2025
c197bdc
Updated const minutes = time.slice(3) --- to const minutes = time.sli…
Mahtem Oct 30, 2025
c6c3d9d
In format-time.js.. commented a repeated function and added explanation
Mahtem Oct 30, 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
19 changes: 15 additions & 4 deletions Sprint-2/1-key-errors/0.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
// Predict and explain first...
// =============> write your prediction here
// =============> I guess we would'nt need to say let in line 8 because str is already decleared as an argument
// within the function capitalise(str).
//

// 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 occured as 'str' is already declared.
// =============> write your new code here

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

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

// =============> write your explanation here
// =============> write your new code here
console.log(capitalise("hello"));
30 changes: 23 additions & 7 deletions Sprint-2/1-key-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,36 @@
// Predict and explain first...

// Why will an error occur when this program runs?
// =============> write your prediction here

// =============> I think, the function convertToPercentage is not called at line 16, and
// there is no any importance of declaring cons decimalNumber as it is already declared.

// 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 appeared indicating 'decimalNumber' has already been declared.

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


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

return percentage;
}

console.log(decimalNumber);
console.log(convertToPercentage(0.5));
console.log(convertToPercentage(0.27));
console.log(convertToPercentage(0.76));

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

// Finally, correct the code to fix the problem
// =============> write your new code here
// The new code run smoothly and retuned "50%"
// decimalNumber is now taken as a parameter.
17 changes: 11 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,23 @@

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

// =============> write your prediction of the error here
// =============> The num should be inside the function square (num) not 3 and square function should be
// called later as square(3)

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

// =============> write the error message here
// =============> function suqare(3) SyntaxError: Unexpected number

// =============> explain this error message here
// =============> 3 was not expected... instead a declaration or paramater like num was expected.

// Finally, correct the code to fix the problem

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

function square(num) {
return num * num;
}
console.log(square(3))

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

// =============> write your prediction here
// =============> In line 6 instead of console.log, I would expect retun a*b; the code will result in
// just printing a*b

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
// =============> After running it returned 320 The result of multiplying 10 and 32 is undefined
// Because the multiply parameters were not taken as paramaters within a retunr.

// 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)}`);
9 changes: 5 additions & 4 deletions Sprint-2/2-mandatory-debug/1.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// Predict and explain first...
// =============> write your prediction here
// =============> The semi colon ; after retunr will results in syntax error.

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

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

// =============> write your explanation here
// =============> Unlike my expectation the code run without error as "The sum of 10 and 32 is undefined"
// Finally, correct the code to fix the problem
// =============> write your new code here

// we just need to delete the ; after return and bring a+b side by side as retun a+b;
31 changes: 21 additions & 10 deletions Sprint-2/2-mandatory-debug/2.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,35 @@
// Predict and explain first...

// Predict the output of the following code:
// =============> Write your prediction here
// =============> The code will first return 3 as string and after calling the function getLastDigit,
// it will not return anything because every number pased will be changed to string.

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

function getLastDigit() {
// 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..
// // =============> my prediction was somehow closer but not exact, the case is parameter num needs to be with the getLastDifit
// function instead of const num = 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)}`);

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

//the case is parameter num needs to be with the getLastDigit function instead of const num = 103.
15 changes: 13 additions & 2 deletions Sprint-2/3-mandatory-implement/1-bmi.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,16 @@
// 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
}

const bmi = weight/(height*height);
return Number(bmi.toFixed(1));

// return the BMI of someone based on their weight and height
}

console.log("The BMI is",calculateBMI(70, 1.73));
console.log(typeof calculateBMI(70,1.73));

// As I see it in the console it looks like a number whilit was a string.
// the code has been updated to return a number as -----return Number(bmi.toFixed(1));
// changing the string into number.
16 changes: 16 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,19 @@
// 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
// Step-2 ----> change to upper case
// Step-3 ----> Replace space with underscore
// Step-4 ----> Return capSnakeCase
17 changes: 17 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,20 @@
// 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: 7 additions & 5 deletions Sprint-2/4-mandatory-interpret/time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,26 @@ 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?
// =============> write your answer here
// =============> Pad is called three (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 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 leftover second is assigned to num as remainingSeconds 61%60

// 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
// =============> 01 the remainingSeconds from passed from pad to num is changed to string and padded as 01
Loading