-
-
Notifications
You must be signed in to change notification settings - Fork 328
London | Jan2026 | Ihor Taradaiko | Sprint 2 | Coursework/sprint 2 #989
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
base: main
Are you sure you want to change the base?
Changes from all commits
8bfaa5f
78d6188
c0b27b0
ed517d4
c53ae02
cb7593e
a56d71b
66ef47c
bac476e
d70c833
fcd1dc1
2fd2099
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,14 +1,18 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // =============> write your prediction here | ||
| // =============> write your prediction here - It will print 320 inside the function, but the template string will show "undefined" because multiply does not return a value. | ||
|
|
||
| function multiply(a, b) { | ||
| console.log(a * b); | ||
| } | ||
|
|
||
| console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); | ||
|
|
||
| // =============> write your explanation here | ||
| // =============> write your explanation here - multiply() uses console.log to display the result, but it doesn't return anything. In JavaScript, a function with no return statement returns undefined, so ${multiply(10, 32)} becomes undefined even though 320 was logged earlier. | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
| function multiplyFixed(a, b) { | ||
| return a * b; | ||
| } | ||
| console.log(`The result of multiplying 10 and 32 is ${multiplyFixed(10, 32)}`); |
|
Contributor
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. Why not try completing the implementation of
Author
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. I was too lazy, will try to.
Contributor
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. That's never a good excuse! |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,23 +3,30 @@ | |
| // Your task is to write tests for as many different groups of input data or edge cases as you can, and fix any bugs you find. | ||
|
|
||
| function formatAs12HourClock(time) { | ||
| const hours = Number(time.slice(0, 2)); | ||
| if (hours > 12) { | ||
| return `${hours - 12}:00 pm`; | ||
| const hours = Number(time.slice(0, 2)); | ||
| const minutes = time.slice(3, 5); | ||
|
Contributor
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.
|
||
| let ampm = "am"; | ||
| let newHours = hours; | ||
|
|
||
| if (hours === 0) { | ||
| newHours = 12; // midnight | ||
| } else if (hours === 12) { | ||
| ampm = "pm"; // noon | ||
| } else if (hours > 12) { | ||
| newHours = hours - 12; | ||
| ampm = "pm"; | ||
| } | ||
| return `${time} am`; | ||
|
|
||
| const showHours = newHours.toString().padStart(2, "0"); | ||
| return `${showHours}:${minutes} ${ampm}`; | ||
| } | ||
|
|
||
| const currentOutput = formatAs12HourClock("08:00"); | ||
| const targetOutput = "08:00 am"; | ||
| console.assert( | ||
| currentOutput === targetOutput, | ||
| `current output: ${currentOutput}, target output: ${targetOutput}` | ||
| ); | ||
| // Now let's test different times | ||
|
|
||
| const currentOutput2 = formatAs12HourClock("23:00"); | ||
| const targetOutput2 = "11:00 pm"; | ||
| console.assert( | ||
| currentOutput2 === targetOutput2, | ||
| `current output: ${currentOutput2}, target output: ${targetOutput2}` | ||
| ); | ||
| console.log(formatAs12HourClock("00:00")); | ||
| console.log(formatAs12HourClock("00:01")); | ||
| console.log(formatAs12HourClock("08:00")); | ||
| console.log(formatAs12HourClock("11:59")); | ||
| console.log(formatAs12HourClock("12:00")); | ||
| console.log(formatAs12HourClock("13:45")); | ||
| console.log(formatAs12HourClock("23:14")); | ||
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.
What do you expect from the following function calls?
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.
Aren't those the same?
3
3
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.
Not the same result. You can test them, and use AI to find out why.
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.
Oh, I didn't know that! The JS auto considers there is ";" after return if there is nothing else in the row