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

LONDON001/LOVETH-CLARA-OKAFOR/Module-Structuring-and-Testing-Data/WEEK2-/SPRINT-2 #228

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Self checklist
- [ ] I have committed my files one by one, on purpose, and for a reason
- [ ] I have titled my PR with COHORT_NAME | FIRST_NAME LAST_NAME | REPO_NAME | WEEK
- [ ] I have tested my changes
- [ ] My changes follow the [style guide](https://curriculum.codeyourfuture.io/guides/contributing/)
- [ ] My changes follow the [style guide](https://syllabus.codeyourfuture.io/guides/code-style-guide/)
- [ ] My changes meet the [requirements](./README.md) of this task

## Changelist
Expand Down
1 change: 1 addition & 0 deletions Sprint-2/debug/0.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Predict and explain first...
// Prediction : I think the function won't return anything because it's using console.log() and not return.
Copy link

Choose a reason for hiding this comment

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

Todo

The instructions in readme.md also ask for "correcting the code".


function multiply(a, b) {
console.log(a * b);
Expand Down
11 changes: 11 additions & 0 deletions Sprint-2/debug/1.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
// Predict and explain first...
// Prediction : it will return "the sum of 10 and 32 is null". Because the function returns something but it's null.
Copy link

Choose a reason for hiding this comment

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

undefined is not the same as null in JS. So which value is returned from the original function?


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

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

// Predict and explain first...

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

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

Choose a reason for hiding this comment

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

Todo

The current script still does not show the sum as 42. You also need to correct the code in the function.

2 changes: 1 addition & 1 deletion Sprint-2/debug/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ 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
3 changes: 2 additions & 1 deletion Sprint-2/errors/0.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
// 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)}`; // No `let`, just reassign
Copy link

Choose a reason for hiding this comment

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

Alternatively, you can declare a new variable or just return the value of the expression (without storing the value in a variable first).

return str;
}
4 changes: 1 addition & 3 deletions Sprint-2/errors/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
// 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);
console.log(convertToPercentage(0.5)); // Outputs "50%"
8 changes: 3 additions & 5 deletions Sprint-2/errors/2.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@

// Predict and explain first...

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

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

console.log(square(3)); // Outputs: 9


18 changes: 18 additions & 0 deletions Sprint-2/extend/format-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,21 @@ console.assert(
currentOutput2 === targetOutput2,
`current output: ${currentOutput2}, target output: ${targetOutput2}`
);

const tests = [
{ input: "08:00", expected: "08:00 am" },
{ input: "23:00", expected: "11:00 pm" },
{ input: "00:00", expected: "12:00 am" },
{ input: "12:00", expected: "12:00 pm" },
{ input: "00:01", expected: "12:01 am" },
{ input: "12:01", expected: "12:01 pm" },
{ input: "13:00", expected: "1:00 pm" },
];
Copy link

Choose a reason for hiding this comment

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

Todo

You also need fix the function if any test fails.


tests.forEach(({ input, expected }) => {
const output = formatAs12HourClock(input);
console.assert(
output === expected,
`Test failed for input "${input}". Output: "${output}", Expected: "${expected}"`
);
});
13 changes: 13 additions & 0 deletions Sprint-2/implement/bmi.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,16 @@
// Given someone's weight in kg and height in metres
// Then when we call this function with the weight and height
// It should return their Body Mass Index to 1 decimal place


function calculateBMI(weight, height) {
// Step 1: Square the height
const heightSquared = height ** 2;

// Step 2: Divide weight by height squared
const bmi = weight / heightSquared;

// Step 3: Return the result to 1 decimal place
return parseFloat(bmi.toFixed(1));
}

13 changes: 13 additions & 0 deletions Sprint-2/implement/cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,16 @@

// You will need to come up with an appropriate name for the function
// Use the string documentation to help you find a solution


function toUpperSnakeCase(input) {
// Step 1: Replace spaces with underscores
const snakeCase = input.replace(/ /g, "_");

// Step 2: Convert the string to uppercase
const upperSnakeCase = snakeCase.toUpperCase();

// Step 3: Return the result
return upperSnakeCase;
}

10 changes: 10 additions & 0 deletions Sprint-2/implement/to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,13 @@
// 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(kilograms) {
Copy link

Choose a reason for hiding this comment

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

Todo

If you refer to interpret/to-pounds.js in Sprint 1, you will find the code there is to convert pence string in the form "399p" to British pound "£3.99". This function should be based on those code.

// Convert kilograms to pounds (1 kg = 2.20462 pounds)
const pounds = kilograms * 2.20462;

// Return the result, rounded to 2 decimal places
return parseFloat(pounds.toFixed(2));
}

10 changes: 10 additions & 0 deletions Sprint-2/implement/vat.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,13 @@
// Given a number,
// When I call this function with a number
// it returns the new price with VAT added on


function addVAT(price) {
// Multiply the price by 1.2 to add 20% VAT
const vatInclusivePrice = price * 1.2;

// Return the result, rounded to 2 decimal places
return parseFloat(vatInclusivePrice.toFixed(2));
}

3 changes: 3 additions & 0 deletions Sprint-2/interpret/time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ function formatTimeDisplay(seconds) {
// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer

// e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer

Copy link

Choose a reason for hiding this comment

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

Todo

In this exercise, you need to answer questions (a)-(e) by tracing the execution of the code (that is, figure out in what order every statement and every function call is executed) .


return `${pad(0)}:${pad(1)}:${pad(1)}`; // "00:01:01"