generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 116
ITP_GLASGOW_MAR | HANNA_MYKYTIUK | MODULE_STRUCTURING_AND_TESTING_DATA | SPRINT_2 #441
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
Open
HannaOdud
wants to merge
7
commits into
CodeYourFuture:main
Choose a base branch
from
HannaOdud:coursework/sprint2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f4e9c6b
key implementation exercises
HannaOdud 6c4cfde
mandatory rewrite exercises
HannaOdud 980fac0
mandatory practice exercises
HannaOdud 3ee1a41
stretch-investigate exercises
HannaOdud eba5d0c
Sprint 2
HannaOdud 5de2a8e
fixes to sprint 2
HannaOdud 06bd8cf
fix2 for sprint2
HannaOdud File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,40 @@ | ||
// Predict and explain first... | ||
|
||
//it won't work | ||
// Predict the output of the following code: | ||
// =============> Write your prediction here | ||
// I've just checked | ||
//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 | ||
// =============> write the output here | ||
// 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 | ||
// because of const num=103 | ||
// Finally, correct the code to fix the problem | ||
// =============> write your new code here | ||
|
||
// This program should tell the user the last digit of each number. | ||
|
||
|
||
|
||
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)}`); | ||
|
||
// Explain why getLastDigit is not working properly - correct the problem | ||
//function getLastDigit(num) - should be like that |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,13 @@ | |
|
||
function formatAs12HourClock(time) { | ||
const hours = Number(time.slice(0, 2)); | ||
const minutes = time.slice(-2); | ||
if (hours > 12) { | ||
return `${hours - 12}:00 pm`; | ||
return `${hours - 12}:${minutes} pm`; | ||
} else if ( hours == 0 ){ | ||
return `12:${minutes} am`; | ||
} else if ( hours == 12 ){ | ||
return `12:${minutes} pm`; | ||
} | ||
return `${time} am`; | ||
} | ||
|
@@ -23,3 +28,36 @@ console.assert( | |
currentOutput2 === targetOutput2, | ||
`current output: ${currentOutput2}, target output: ${targetOutput2}` | ||
); | ||
|
||
////////////// | ||
// hours > 12 and minutes NOT 00 | ||
const currentOutput3 = formatAs12HourClock("23:45"); | ||
const targetOutput3 = "11:45 pm"; | ||
console.assert( | ||
currentOutput3 === targetOutput3, | ||
`current output: ${currentOutput3}, target output: ${targetOutput3}` | ||
); | ||
|
||
// hours < 12 and minutes NOT 00 | ||
const currentOutput4 = formatAs12HourClock("09:13"); | ||
const targetOutput4 = "09:13 am"; | ||
console.assert( | ||
currentOutput4 === targetOutput4, | ||
`current output: ${currentOutput4}, target output: ${targetOutput4}` | ||
); | ||
|
||
// hours = 00 and minutes = 00 | ||
const currentOutput5 = formatAs12HourClock("00:00"); | ||
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 think "00:00" should be converted to "12:00 am" (midnight). |
||
const targetOutput5 = "12:00 am"; | ||
console.assert( | ||
currentOutput5 === targetOutput5, | ||
`current output: ${currentOutput5}, target output: ${targetOutput5}` | ||
); | ||
|
||
// hours = 12 and minutes = 00 | ||
const currentOutput6 = formatAs12HourClock("12:00"); | ||
const targetOutput6 = "12: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. Does your function return this expected value? |
||
console.assert( | ||
currentOutput6 === targetOutput6, | ||
`current output: ${currentOutput6}, target output: ${targetOutput6}` | ||
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think the function is expected to compute and return a percentage string when given a number; it should not output
0.5
every time the function is called.If we want to output 0.25 as 25%, we could write
console.log( convertToPercentage(0.25) );
outside the function.