generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 237
London | 25-ITP-May | Alexandru Pocovnicu | Sprint 2 | Acoursework #728
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
alexandru-pocovnicu
wants to merge
13
commits into
CodeYourFuture:main
Choose a base branch
from
alexandru-pocovnicu:acoursework/sprint-2`
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
13 commits
Select commit
Hold shift + click to select a range
a318e04
called a function , interpreted the error message
alexandru-pocovnicu 686be02
fixed the code to log the function and not the parameter
alexandru-pocovnicu 763574c
fixed the function to return the square of a number by replacing the …
alexandru-pocovnicu f7173fc
replaced console.log with return inside the function
alexandru-pocovnicu 9bfd01a
removed the semicolon after the "return" and moved "a+b" on the same …
alexandru-pocovnicu 58fda13
removed unused code and updated the parameter
alexandru-pocovnicu 0b055f8
implemented a function that calculates bmi with one decimal
alexandru-pocovnicu b9c50c9
implemented a function that turns a string in to snake uppercase
alexandru-pocovnicu e02e2e7
updated the function to replace all the spaces between words with"_"
alexandru-pocovnicu e9b8d94
created a function that converts pence in to pounds
alexandru-pocovnicu 57ad058
added comments to answer the questions
alexandru-pocovnicu c688a68
wrote test cases for edge cases and updated the function accordingly
alexandru-pocovnicu 6aa1613
fix: add space for readability in time formatting condition
alexandru-pocovnicu 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,27 @@ | ||
// Predict and explain first... | ||
|
||
// Why will an error occur when this program runs? | ||
// =============> write your prediction here | ||
// decimalNumber is already used as a parameter so it can not be used as a variable inside the function, | ||
// the code is logging the parameter instead of the function | ||
|
||
// 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); | ||
|
||
// I'm not sure about what to write here | ||
|
||
// Finally, correct the code to fix the problem | ||
function convertToPercentage(decimalNumber) { | ||
const decimalNumber = 0.5; | ||
const percentage = `${decimalNumber * 100}%`; | ||
|
||
return percentage; | ||
} | ||
|
||
console.log(decimalNumber); | ||
|
||
// =============> write your explanation here | ||
|
||
// Finally, correct the code to fix the problem | ||
// =============> write your new code here | ||
console.log(convertToPercentage(0.9)) |
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,14 +1,18 @@ | ||
// Predict and explain first... | ||
|
||
// =============> write your prediction here | ||
// the function hasn't got a return so the log will be undefined | ||
|
||
function multiply(a, b) { | ||
console.log(a * b); | ||
} | ||
// 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 | ||
// the function hasn't got a return so the log will be undefined | ||
|
||
// 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)}`); |
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,13 +1,18 @@ | ||
// Predict and explain first... | ||
// =============> write your prediction here | ||
// SyntaxError | ||
|
||
// function sum(a, b) { | ||
// return; | ||
// a + b; | ||
// } | ||
|
||
// console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); | ||
|
||
// the function doesn't return anything because there is ";" immediately after "return" and the mathematicall operation is on another line | ||
// Finally, correct the code to fix the problem | ||
function sum(a, b) { | ||
return; | ||
a + b; | ||
return a + b; | ||
|
||
} | ||
|
||
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); | ||
|
||
// =============> write your explanation here | ||
// Finally, correct the code to fix the problem | ||
// =============> write your new code here |
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,33 @@ | ||
// Predict and explain first... | ||
|
||
// Predict the output of the following code: | ||
// =============> Write your prediction here | ||
// num undefined | ||
|
||
const num = 103; | ||
// const num = 103; | ||
|
||
function getLastDigit() { | ||
// 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)}`); | ||
|
||
// Now run the code and compare the output to your prediction | ||
// 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 | ||
// because num is declared as a global variable and it never changes, should be used as parameter | ||
// Finally, correct the code to fix the problem | ||
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)}`); | ||
|
||
// Now run the code and compare the output to your prediction | ||
// =============> write the output here | ||
// Explain why the output is the way it is | ||
// =============> write your explanation here | ||
// 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. | ||
// Explain why getLastDigit is not working properly - correct the problem |
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,15 @@ | |
|
||
function formatAs12HourClock(time) { | ||
const hours = Number(time.slice(0, 2)); | ||
const minutes=time.slice(3,5) | ||
if(hours<1){ | ||
return `12:${minutes} am` | ||
} | ||
if(hours==12 && minutes==00){ | ||
return "12:00 pm" | ||
} | ||
if (hours > 12) { | ||
return `${hours - 12}:00 pm`; | ||
return `${hours - 12}:${minutes} pm`; | ||
} | ||
return `${time} am`; | ||
} | ||
Comment on lines
+8
to
18
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.
|
||
|
@@ -23,3 +30,34 @@ console.assert( | |
currentOutput2 === targetOutput2, | ||
`current output: ${currentOutput2}, target output: ${targetOutput2}` | ||
); | ||
|
||
const currentOutput3 = formatAs12HourClock("23:33"); | ||
const targetOutput3 = "11:33 pm"; | ||
console.assert( | ||
currentOutput3 === targetOutput3, | ||
`current output: ${currentOutput3}, target output: ${targetOutput3}` | ||
); | ||
|
||
const currentOutput4 = formatAs12HourClock("11:59"); | ||
const targetOutput4 = "11:59 am"; | ||
console.assert( | ||
currentOutput4 === targetOutput4, | ||
`current output: ${currentOutput4}, target output: ${targetOutput4}` | ||
); | ||
|
||
const currentOutput5 = formatAs12HourClock("00:01"); | ||
const targetOutput5 = "12:01 am"; | ||
console.assert( | ||
currentOutput5 === targetOutput5, | ||
`current output: ${currentOutput5}, target output: ${targetOutput5}` | ||
); | ||
|
||
const currentOutput6 = formatAs12HourClock("12:00"); | ||
const targetOutput6 = "12:00 pm"; | ||
console.assert( | ||
currentOutput6 === targetOutput6, | ||
`current output: ${currentOutput6}, target output: ${targetOutput6}` | ||
); | ||
|
||
|
||
|
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.
VSCode to help you indent the code.
Note: There are simpler ways (which involve using some built-in functions) to truncate/round a number to 1 decimal place.