Skip to content
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

WEST MIDLANDS-JAN-ITP|SEGUN FOLAYAN|STRCURING AND TESTING DATA|SPRINT2 #429

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
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
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: The code will not run because "let" should not be use in a function.

// call the function capitalise with a string input
// interpret the error message and figure out why an error is occurring
// call the function capitalise with a string input: done
// interpret the error message and figure out why an error is occurring: says string has already been declared. As said earlier "let" should be eliminated

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

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

// =============> write your explanation here:
// Let is not needed to declare a variable inside a function.
// =============> write your new code here
function capitalise(str) {
str = `${str[0].toUpperCase()}${str.slice(1)}`;
return str;
}
15 changes: 12 additions & 3 deletions Sprint-2/1-key-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Predict and explain first...

// Why will an error occur when this program runs?
// =============> write your prediction here
// Why will an error occur when this program runs? decimalNumber should be assigned a value outside the function only.
// =============> write your prediction here: const decimalNumber = 0.5 will give an error message.

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

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

console.log(decimalNumber);

// =============> write your explanation here
// =============> write your explanation here: The re-assignment of decimal number inside the function is unecessary

// 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.5));
12 changes: 8 additions & 4 deletions Sprint-2/1-key-errors/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@

// 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: There is going to be an error message. As there should be a variable in place of "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: As there should be a variable in place of "3"

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

// Finally, correct the code to fix the problem

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


console.log(square(3));
13 changes: 10 additions & 3 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
// =============> write your prediction here: the function has no return. Hence multiply ${multiply(10, 32)} will return 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:
// console.log(a*b) logs the result of the multiplication to the console but does not return any value.

// 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: 8 additions & 1 deletion Sprint-2/2-mandatory-debug/1.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
// Predict and explain first...
// =============> write your prediction here
// ${sum(10, 32)} will return undefined.

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
//Inside the function, return should not be followed by a semi-colon
// 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)}`);
17 changes: 17 additions & 0 deletions Sprint-2/2-mandatory-debug/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

// Predict the output of the following code:
// =============> Write your prediction here
// The code will only output for the number declared first

const num = 103;

Expand All @@ -15,10 +16,26 @@ 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
//Output
//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 code will also return the last digit of num because the code does not accept parameters
// Finally, correct the code to fix the problem
// =============> write your new code here

const num = 103;

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 BM = weight/(height**2) // These are modifications based on review.
const BMI = BM.toFixed(1); //Theses are modifications based on review.
return BMI
}
console.log(calculateBMI(60,1.65));
4 changes: 4 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,7 @@
// 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 ChangeCasePluseSnake(str){
return str.toUpperCase().replace(" ","_");
};
console.log(ChangeCasePluseSnake("Hello World"));
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 penceChange(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(penceChange("300p"));
8 changes: 6 additions & 2 deletions Sprint-2/4-mandatory-interpret/time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,29 @@ 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 will be called three timesgit

// 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
//Value assigned will be 0

// c) What is the return value of pad is called for the first time?
// =============> write your answer here

// The return value 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 assigned value 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
// The return value is 01
3 changes: 3 additions & 0 deletions Sprint-3/1-key-implement/1-get-angle-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

function getAngleType(angle) {
if (angle === 90) return "Right angle";
else if (angle < 90) return "Acute angle";
else if (angle >90 && angle <180) return "Obtuse angle";
// read to the end, complete line 36, then pass your test here
}

Expand Down Expand Up @@ -43,6 +45,7 @@ assertEquals(acute, "Acute angle");
// When the angle is greater than 90 degrees and less than 180 degrees,
// Then the function should return "Obtuse angle"
const obtuse = getAngleType(120);
assertEquals(obtuse,"Obtuse angle");
// ====> write your test here, and then add a line to pass the test in the function above

// Case 4: Identify Straight Angles:
Expand Down