-
-
Notifications
You must be signed in to change notification settings - Fork 72
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
base: main
Are you sure you want to change the base?
Changes from all commits
f708d7e
fe5755d
e1bd38e
ae1b7d9
86371c1
5b70c0b
6e09604
dcd0dc6
2633c51
318675e
b93c089
3f0cc12
da91ca6
c6a176c
5997920
bd38801
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
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)}`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TodoThe current script still does not show the sum as 42. You also need to correct the code in the function. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} |
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 | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" }, | ||
]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TodoYou 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}"` | ||
); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TodoIf you refer to |
||
// 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)); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TodoIn 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" |
There was a problem hiding this comment.
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".