Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 0 additions & 2 deletions .github/FUNDING.yml

This file was deleted.

36 changes: 0 additions & 36 deletions .github/pull_request_template.md

This file was deleted.

18 changes: 0 additions & 18 deletions .github/workflows/validate-pr-metadata.yml

This file was deleted.

Binary file added Sprint-1/Sprint1 Internship email.docx
Binary file not shown.
17 changes: 12 additions & 5 deletions Sprint-2/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

// The code will throw an error because the variable 'str' is being redeclared inside the function 'capitalise'. The error message is likely to be a syntax error.
// 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 error is occurring because we are trying to declare a variable 'str' inside the function that has the same name as the parameter 'str'.To fix this problem, create an variable with a new name Newstr . So we would change the line to: Newstr = `${str[0].toUpperCase()}${str.slice(1)}`;
// =============> write your new code here
function capitalise(str) {
let Newstr = `${str[0].toUpperCase()}${str.slice(1)}`;
return Newstr;
}
str="hello world";
console.log(capitalise(str));
21 changes: 15 additions & 6 deletions Sprint-2/1-key-errors/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,28 @@

// Why will an error occur when this program runs?
// =============> write your prediction here
// The error will occur because we are trying to declare a variable with the same name as the parameter of the function. The error message will likely indicate that there is a syntax error or that the variable 'str' has already been 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}%`;
//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
// The error is occurring because we are trying to declare a variable 'decimalNumber' inside the function that has the same name as the parameter 'decimalNumber'. To fix this problem, we can different variable name for the parameter or the variable inside the function. For example, we could change the line to: const decimalNum = 0.5; and then use 'decimalNum' instead of 'decimalNumber' in the rest of the function.

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

function convertToPercentage(decimalNumber) {
const decimalNum = 0.5;
const percentage = `${decimalNum * 100}%`;
return percentage;
}
console.log(convertToPercentage(0.5));
16 changes: 10 additions & 6 deletions Sprint-2/1-key-errors/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@
// this function should square any number but instead we're going to get an error

// =============> write your prediction of the error here

function square(3) {
return num * num;
}
// The error will occur because we are trying to declare a function with a parameter that is not a valid variable name. The parameter '3' is not a valid variable name in JavaScript, and this will likely result in a syntax error.
//function square(3) {
// return num * num;
//}

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

// SyntaxError: Unexpected number '3'
// =============> explain this error message here

// The error message is indicating that there is a syntax error in the code because we are trying to use a number '3' as a parameter name in the function declaration, which is not allowed in JavaScript. Parameter names must be valid identifiers, which cannot start with a number. To fix this error, we need to change the parameter name to a valid identifier, such as 'num' or 'x'. So we would change the line to: function square(num) { return num * num; }
// Finally, correct the code to fix the problem

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


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

// =============> write your prediction here
// The error will occur because the function 'sum' is not returning the result of multiplying 'a' and 'b'. Instead, it is returning 'undefined' due to the function being incomplete. The error message will likely indicate that the result of the sum is 'undefined' when we try to log it to the console.

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
// The error is occurring because the function 'multiply' is not returning any value. In JavaScript, if a function does not explicitly return a value, it returns 'undefined' by default. To fix this problem, we need to add a return statement to the function that returns the result of multiplying 'a' and 'b'. For example, we could change the line to: return a * b; so that the function will return the correct result when called.

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

20 changes: 14 additions & 6 deletions Sprint-2/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
//The error will occur because the function 'sum' is not returning the result of summing 'a' and 'b'. Instead, it is returning 'undefined' due to the function being incomplete. The error message will likely indicate that the result of the sum is 'undefined' when we try to log it to the console.
//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
// The error is occurring because the function 'sum' is not returning any value. In JavaScript, if a function does not explicitly return a value, it returns 'undefined' by default. To fix this problem, we need to add a return statement to the function that returns the result of summing 'a' and 'b'. For example, we could change the line to: return a + b; so that the function will return the correct result when called.


// 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)}`);
28 changes: 21 additions & 7 deletions Sprint-2/2-mandatory-debug/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,37 @@

// Predict the output of the following code:
// =============> Write your prediction here
//the output will be: an error because the function getLastDigit is not defined to take any parameters, but we are trying to pass a number as an argument when we call the function. The error message will likely indicate that getLastDigit is not a function or that it cannot be called with arguments.

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
//it does run but returns the last digit of the number 103 for all three calls to getLastDigit, which is not the expected behavior. The output will be:
// 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 function getLastDigit is not taking any parameters, so it always returns the last digit of the global variable 'num', which is 103. The function should take a number as a parameter and return the last digit of that number.

// 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
6 changes: 5 additions & 1 deletion Sprint-2/3-mandatory-implement/1-bmi.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@

function calculateBMI(weight, height) {
// return the BMI of someone based off their weight and height
}
const bmi = weight / (height ^2);
return Math.round(bmi * 10) / 10;
}
console.log(calculateBMI(70, 1.73)); // should return 23.4

9 changes: 9 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,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 toUpperSnakeCase(str) {
// return the string in UPPER_SNAKE_CASE
const upperStr = str.toUpperCase();
const snakeCaseStr = upperStr.replace(/ /g, '_');
return snakeCaseStr;
}
console.log(toUpperSnakeCase("hello there")); // should return "HELLO_THERE"
console.log(toUpperSnakeCase("lord of the rings")); // should return "LORD_OF_THE_RINGS"
20 changes: 20 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,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("123p")); // should return "£1.23"
console.log(toPounds("5p")); // should return "£0.05"
console.log(toPounds("75p")); // should return "£0.75"
console.log(toPounds("1000p")); // should return "£10.00"
5 changes: 5 additions & 0 deletions Sprint-2/4-mandatory-interpret/time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,22 @@ function formatTimeDisplay(seconds) {

// a) When formatTimeDisplay is called how many times will pad be called?
// =============> write your answer here
// The function pad will be called three times when formatTimeDisplay is called, once for each of; hours, minutes, and seconds.These are then passed as an argument to the pad function to ensure that they are displayed with two digits in the final output string.

// 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 when pad is called for the first time is the totalHours value, which is 0. The value of 61 seconds is only one minute and one second, any value that includes hours must be in excess of 3600 seconds.

// c) What is the return value of pad is called for the first time?
// =============> write your answer here
// The return value of pad when it is called for the first time is "00". This is because the totalHours value is 0, and when it is converted to a string and passed to the pad function, it will be padded with a leading zero to ensure that it has two digits, resulting in "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 when pad is called for the last time in this program is the remainingSeconds value, which is 1. This is because the input of 61 seconds results in 1 second remaining after accounting for the full minute.

// 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
//This value displayed with two digits in the final output string, resulting in "01".
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,20 @@

function getAngleType(angle) {
// TODO: Implement this function
}
if (angle > 0 && angle < 90) {
return "Acute angle";
} else if (angle === 90) {
return "Right angle";
} else if (angle > 90 && angle < 180) {
return "Obtuse angle";
} else if (angle === 180) {
return "Straight angle";
} else if (angle > 180 && angle < 360) {
return "Reflex angle";
} else {
return "Invalid angle";
}
}

// The line below allows us to load the getAngleType function into tests in other files.
// This will be useful in the "rewrite tests with jest" step.
Expand All @@ -35,3 +48,13 @@ function assertEquals(actualOutput, targetOutput) {
// Example: Identify Right Angles
const right = getAngleType(90);
assertEquals(right, "Right angle");
const acute = getAngleType(45);
assertEquals(acute, "Acute angle");
const obtuse = getAngleType(120);
assertEquals(obtuse, "Obtuse angle");
const straight = getAngleType(180);
assertEquals(straight, "Straight angle");
const reflex = getAngleType(270);
assertEquals(reflex, "Reflex angle");
const invalid = getAngleType(400);
assertEquals(invalid, "Invalid angle");
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,17 @@
// execute the code to ensure all tests pass.

function isProperFraction(numerator, denominator) {


// TODO: Implement this function
if (denominator === 0) {
return false;
}
if (Math.abs(numerator) < Math.abs(denominator)) {
return true;
} else {
return false;
}
}

// The line below allows us to load the isProperFraction function into tests in other files.
Expand All @@ -24,10 +34,19 @@ function assertEquals(actualOutput, targetOutput) {
actualOutput === targetOutput,
`Expected ${actualOutput} to equal ${targetOutput}`
);

}

// TODO: Write tests to cover all cases.
// What combinations of numerators and denominators should you test?

// Example: 1/2 is a proper fraction
assertEquals(isProperFraction(1, 2), true);
assertEquals(isProperFraction(2, 1), false);
assertEquals(isProperFraction(-1, 2), true);
assertEquals(isProperFraction(1, -2), true);
assertEquals(isProperFraction(0, 2), true);
assertEquals(isProperFraction(2, 2), false);
assertEquals(isProperFraction(-2, -1), false);
assertEquals(isProperFraction(-2, -2), false);
assertEquals(isProperFraction(1, 0), false);
Loading
Loading