Skip to content

London|May-2025|Alexandru Pocovnicu|Structuring and testing data/Coursework/sprint 2 #514

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
e170c4c
made my prediction and corrected the code on line 8, removed 'let'
alexandru-pocovnicu Jun 10, 2025
5b4a506
made a prediction(wrong) and corrected the code
alexandru-pocovnicu Jun 10, 2025
4f6fb22
made a prediction, changed the code
alexandru-pocovnicu Jun 10, 2025
0e85fa5
made my prediction and corrected the code
alexandru-pocovnicu Jun 10, 2025
36eab2f
made my prediction, corrected the code
alexandru-pocovnicu Jun 10, 2025
36ee959
made a prediction ( i am something of a nostradamus by now) corrected…
alexandru-pocovnicu Jun 10, 2025
501c5d5
wrote a function to find out my bmi
alexandru-pocovnicu Jun 10, 2025
7e0e2e8
converted a string to snake upper case
alexandru-pocovnicu Jun 10, 2025
0588bc9
turned the code in to one fuction called toPounds
alexandru-pocovnicu Jun 10, 2025
9286c0e
i interpreted the functions and wrote the answers in the comments
alexandru-pocovnicu Jun 11, 2025
41ab3ae
i wrote tests for as many edge cases i cold think of and fixed the bu…
alexandru-pocovnicu Jun 11, 2025
0e4dc60
updated the answer for the first question
alexandru-pocovnicu Jul 1, 2025
c5909c1
deleted decimalNumber=o.5
alexandru-pocovnicu Jul 1, 2025
70ce1a9
corrected my prediction
alexandru-pocovnicu Jul 1, 2025
541e4f9
added a value to the console.log to check if it works
alexandru-pocovnicu Jul 1, 2025
e1a40af
added assert for 23:45
alexandru-pocovnicu Jul 2, 2025
1d99926
added assert for 13:30
alexandru-pocovnicu Jul 2, 2025
fc95e06
added assert and code for 00:00
alexandru-pocovnicu Jul 2, 2025
fcde0f6
fix: correct comparison for hours in formatAs12HourClock function
alexandru-pocovnicu Jul 19, 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
14 changes: 10 additions & 4 deletions Sprint-2/1-key-errors/0.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
// Predict and explain first...
// =============> write your prediction here
// =============> write your prediction here: "str" is already used as a parameter , i don't know if we gonna get an error or undefined

// 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)}`;
str = `${str[0].toUpperCase()}${str.slice(1)}`;
return str;
}
capitalise("hello");
// =============> write your explanation here: the error occurs because "str" has already been declared when was used as a parameter

// =============> write your explanation here
// =============> write your new code here
/* =============> write your new code here:
function capitalise(str) {
str = `${str[0].toUpperCase()}${str.slice(1)}`;
return str;
}
capitalise("hello");*/
20 changes: 14 additions & 6 deletions Sprint-2/1-key-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
// Predict and explain first...

// Why will an error occur when this program runs?
// =============> write your prediction here
/* =============> write your prediction here: because on line 11
decimalNumber is already used as parameter so it can't be declared again inside the function*/

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

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

return percentage;
}

console.log(decimalNumber);

console.log(convertToPercentage(7));//ReferenceError: decimalNumber is not defined
console.log(convertToPercentage(0.5));
// =============> write your explanation here

// Finally, correct the code to fix the problem
// =============> write your new code here
=============> write your new code here:*/
function convertToPercentage(decimalNumber) {

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

return percentage;
}
console.log(convertToPercentage(0.5));
12 changes: 7 additions & 5 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
// =============> write your prediction of the error here: num is undefined

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

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

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

// Finally, correct the code to fix the problem

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


function square(num) {
return num * num;
}
14 changes: 9 additions & 5 deletions Sprint-2/2-mandatory-debug/0.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
// Predict and explain first...

// =============> write your prediction here

function multiply(a, b) {
// =============> write your prediction here: instead of "console.log(a * b);" should be "return..", might get undefined
/*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
// =============> write your explanation here:instead of "console.log(a * b);" should be "return.."

// 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)}`);
22 changes: 14 additions & 8 deletions Sprint-2/2-mandatory-debug/1.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
// Predict and explain first...
// =============> write your prediction here
// =============> write your prediction here: Syntax error: The sum of 10 and 32 is 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)}`);
// console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);

// =============> write your explanation here
// Finally, correct the code to fix the problem
// =============> write your explanation here: the function will return 'undefined' because there is nothing coming after 'return'
// =============> write your new code here
function sum(a, b) {
return a + b;

}

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

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

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

function getLastDigit() {
/*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)}`);
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
// =============> 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 const num has been assigned the value 103 and that's the value the fuction always uses
// Finally, correct the code to fix the problem
// =============> write your new code here
// =============> 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
// Explain why getLastDigit is not working properly - correct the problem: see above-line 22
7 changes: 5 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,8 @@
// 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);
const roundedBmi = Math.round(Bmi * 10) / 10;
return roundedBmi;
}
console.log(calculateBMI(90, 1.79));
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(abc){
const convertToUpperCase=abc.toUpperCase();
const replaceSpace=convertToUpperCase.replaceAll(" ","_");
return replaceSpace
}
console.log(UpperSnakeCase("hello, how are you?"))
23 changes: 23 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,26 @@
// 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){
penceString = String(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("900p"));
console.log(toPounds("90p"));
console.log(toPounds("1209m"));
11 changes: 6 additions & 5 deletions Sprint-2/4-mandatory-interpret/time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,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
// =============> 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
// =============> write your answer here: 0

// c) What is the return value of pad is called for the first time?
// =============> write your answer here
// =============> 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
// =============> write your answer here:1 because the remaining seconds is "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
// =============> write your answer here:01 because .padStart(2,"0") adds a "0"
54 changes: 52 additions & 2 deletions Sprint-2/5-stretch-extend/format-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@

function formatAs12HourClock(time) {
const hours = Number(time.slice(0, 2));
if (hours > 12) {
return `${hours - 12}:00 pm`;
const minutes=(time.slice(3,5));
if(hours===0)return `12:${minutes} am`
if(hours===24){
return `00:${minutes} am`
}
else if(hours===12){
return `12:${minutes} pm`
}
else if (hours > 12) {
return `${hours - 12}:${minutes} pm`;
}
return `${time} am`;
}
Expand All @@ -23,3 +31,45 @@ console.assert(
currentOutput2 === targetOutput2,
`current output: ${currentOutput2}, target output: ${targetOutput2}`
);
const currentOutput3 = formatAs12HourClock("23:59");
const targetOutput3 = "11:59 pm";
console.assert(
currentOutput3 === targetOutput3,
`current output: ${currentOutput3}, target output: ${targetOutput3}`
);
const currentOutput4 = formatAs12HourClock("24:00");
const targetOutput4 = "00:00 am";
console.assert(
currentOutput4 === targetOutput4,
`current output: ${currentOutput4}, target output: ${targetOutput4}`
);
const currentOutput5 = formatAs12HourClock("12:01");
const targetOutput5 = "12:01 pm";
console.assert(
currentOutput5 === targetOutput5,
`current output: ${currentOutput5}, target output: ${targetOutput5}`
);
const currentOutput6 = formatAs12HourClock("11:59");
const targetOutput6 = "11:59 am";
console.assert(
currentOutput6 === targetOutput6,
`current output: ${currentOutput6}, target output: ${targetOutput6}`
);
const currentOutput7 = formatAs12HourClock("23:45");
const targetOutput7 = "11:45 pm";
console.assert(
currentOutput7 === targetOutput7,
`current output: ${currentOutput7}, target output: ${targetOutput7}`
);
const currentOutput8 = formatAs12HourClock("13:30");
const targetOutput8= "1:30 pm";
console.assert(
currentOutput8 === targetOutput8,
`current output: ${currentOutput8}, target output: ${targetOutput8}`
);
const currentOutput9 = formatAs12HourClock("00:00");
const targetOutput9= "12:00 am";
console.assert(
currentOutput9 === targetOutput9,
`current output: ${currentOutput9}, target output: ${targetOutput9}`
);