-
-
Notifications
You must be signed in to change notification settings - Fork 389
London | 26-ITP_May | Vito Moratti | Sprint 2 | Coursework/sprint 2 #1429
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
vmoratti
wants to merge
44
commits into
CodeYourFuture:main
Choose a base branch
from
vmoratti:coursework/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
44 commits
Select commit
Hold shift + click to select a range
72a2114
add comment explaining what like 3 is doing
vmoratti e988493
use string indexing to get the initials
vmoratti 541c57c
figure out what (num) represents, add comment
vmoratti 2c05e7e
solve the slicing proble,create dir variabe and ext variable
vmoratti 0a2e2ac
answer the question in the exercse
vmoratti 697ddfc
change const to let, add comment
vmoratti 704b717
fix the error, comment on it
vmoratti 4c49b91
add question in comments
vmoratti 6003611
fix problem
vmoratti 06ed7a8
answer all the questions in the exercise
vmoratti a6d738a
Answer questions in the exercise
vmoratti c00ebcd
add comments to explain code
vmoratti c89d0c3
can't undestand instructions
vmoratti c1f0514
answer questions in objects.md
vmoratti 71235b3
solve the code error message
vmoratti fa98548
fix proble, answer questions
vmoratti 4b743c8
fix code, explain fix
vmoratti 4919640
fix code, write explanation
vmoratti 6a9bf82
explain and fix code
vmoratti 9560e8d
explain and fix the code
vmoratti 6187040
create function to calculate BMI
vmoratti 82a2abd
implement function for UPPER_SNAKE
vmoratti ca2e82e
implement function to convert to pounds
vmoratti c81c5df
Answer questions
vmoratti 301c8f1
write tests, fix bugs
vmoratti 9ccd193
edit comment
vmoratti 3a491f5
Delete Sprint-1/1-key-exercises/1-count.js
vmoratti 9c5bcd0
Delete Sprint-1/4-stretch-explore/objects.md
vmoratti eb98abb
Delete Sprint-1/4-stretch-explore/chrome.md
vmoratti 2d44b64
Delete Sprint-1/2-mandatory-errors/2.js
vmoratti ce208ae
Delete Sprint-1/2-mandatory-errors/4.js
vmoratti e042ab7
Delete Sprint-1/1-key-exercises/2-initials.js
vmoratti 19f6b35
Delete Sprint-1/1-key-exercises/3-paths.js
vmoratti 2c2aeee
Delete Sprint-1/1-key-exercises/4-random.js
vmoratti d43c9fa
Delete Sprint-1/2-mandatory-errors/1.js
vmoratti b68e8ad
Delete Sprint-1/2-mandatory-errors/0.js
vmoratti 712fb63
Delete Sprint-1/2-mandatory-errors/3.js
vmoratti c10a299
Delete Sprint-1/3-mandatory-interpret/1-percentage-change.js
vmoratti 5a6b4c4
Delete Sprint-1/3-mandatory-interpret/2-time-format.js
vmoratti 8ccb9f5
Delete Sprint-1/3-mandatory-interpret/3-to-pounds.js
vmoratti 705c3e2
fix sprint-1 files
vmoratti c56be30
Fix comment formatting in calculateBMI function
vmoratti 6fedd2a
Refactor time formatting and update test cases
vmoratti 1b5fc8a
Modify calculateBMI to return only BMI value
vmoratti 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,40 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // Why will an error occur when this program runs? | ||
| // =============> write your prediction here | ||
|
|
||
| // I think there will be an error as "decimalNumber" variable has already been declared as a parameter in | ||
| // "convertToPercentage" function | ||
| // | ||
| // Try playing computer with the example to work out what is going on | ||
|
|
||
| function convertToPercentage(decimalNumber) { | ||
| /*function convertToPercentage(decimalNumber) { | ||
| const decimalNumber = 0.5; | ||
| const percentage = `${decimalNumber * 100}%`; | ||
|
|
||
| return percentage; | ||
| } | ||
|
|
||
| console.log(decimalNumber); | ||
| console.log(decimalNumber); */ | ||
|
|
||
| // =============> write your explanation here | ||
| // =============Explanation =============== | ||
| // the "decimalNumber" variable is a local variable and can only be seen inside "convertToPercentage" function | ||
| // therefore when called outside the function it triggers "ReferenceError" | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
| // =========correction========= | ||
| // problem can be fixed by moving the variable declaration outside the function | ||
| // and making it global | ||
|
|
||
| // =============> write your new code here | ||
|
|
||
| const decimalNumber = 0.5; | ||
| function convertToPercentage(decimalNumber) { | ||
| const percentage = `${decimalNumber * 100}%`; | ||
|
|
||
| return percentage; | ||
| } | ||
|
|
||
| console.log(decimalNumber); | ||
| console.log(convertToPercentage(decimalNumber)); | ||
|
|
||
|
|
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,24 @@ | ||
|
|
||
| // Predict and explain first BEFORE you run any code... | ||
|
|
||
| // this function should square any number but instead we're going to get an error | ||
|
|
||
| // =============> write your prediction of the error here | ||
|
|
||
| function square(3) { | ||
| //=========Prediction============= | ||
| // I think there will not be en error till we call the function. | ||
| /*function square(num) { | ||
| return num * num; | ||
| } | ||
|
|
||
| console.log(square(5))*/ | ||
| // =============> write the error message here | ||
|
|
||
| // Unexpected number | ||
| // =============> explain this error message here | ||
|
|
||
| // I think it function expects parameter as a variable rather than a number. | ||
| // Finally, correct the code to fix the problem | ||
|
|
||
| // ===========correction========= | ||
| // to correct the code we need to introduce parameter as a variable, rather than a number. | ||
| // that way any number can be passed when function is called. | ||
| // =============> write your new code here | ||
|
|
||
|
|
||
| function square(num) { | ||
| return num * num; | ||
| } | ||
| console.log(square(5)); |
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,25 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // =============> write your prediction here | ||
|
|
||
| function multiply(a, b) { | ||
| //===========Prediction======= | ||
| // I think the code will not produce the desired result as the function is not returning any value | ||
| /*function multiply(a, b) { | ||
| console.log(a * b); | ||
| } | ||
|
|
||
| console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); | ||
| console.log(multiply(3, 5)); | ||
| typeof(multiply(3, 4));*/ | ||
|
|
||
| // =============> write your explanation here | ||
|
|
||
| //===============Explanation========= | ||
| // The function itself prints out the result, but the result has no (type) as such and can not be used as | ||
| // a data type. | ||
| // | ||
| // Finally, correct the code to fix the problem | ||
| //============correction============ | ||
| // To correct the code "return" needs to be introduced. | ||
| // =============> 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,23 @@ | ||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
|
|
||
| // =============explanation========== | ||
| // I think will either give error, or no result at all as there is a ";" semicolon after | ||
| // the return statement and the actual calculation is not assigned to anything. | ||
| function sum(a, b) { | ||
| return; | ||
| a + b; | ||
| a + b; | ||
| } | ||
|
|
||
| console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); | ||
|
|
||
| // =============> write your explanation here | ||
| //==============Explanation=============== | ||
| //To fix the code the ";" must be removed, and the calculation | ||
| //needs to be placed next to the "return" | ||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
| function sum(a, b) { | ||
| return a + b; | ||
| } | ||
|
|
||
| console.log(`The sum of 10 and 32 is ${sum(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
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,25 +1,72 @@ | ||
| // This is the latest solution to the problem from the prep. | ||
| // Make sure to do the prep before you do the coursework | ||
| // 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. | ||
| // 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. | ||
|
|
||
| // This is the latest solution to the problem from the prep. | ||
| // Make sure to do the prep before you do the coursework | ||
| // 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`; | ||
| } | ||
| return `${time} am`; | ||
| const hours = Number(time.slice(0, 2)); // "hours" variable represents first two digits of the time string turned into number | ||
| const minutes = Number(time.slice(-2));// "mninutes" variable represents last two digits of the "time" string converted to number | ||
| if (hours === 12) { | ||
| return `${time}pm` // if time is "12:00" it will show | ||
| //12:00 pm | ||
| } else if (hours === 24 && time.slice(-2) === "00") { | ||
| return `00:00am`; | ||
| } else if (hours === 24 && minutes > 0) { | ||
| return `00:${minutes}am` | ||
|
|
||
| }else if (hours > 12) { | ||
| return `${hours - 12}:${minutes}pm`; | ||
| } | ||
| return `${time}am`; | ||
| } | ||
|
|
||
| const currentOutput = formatAs12HourClock("08:00"); | ||
| const targetOutput = "08:00 am"; | ||
| const targetOutput = "08:00am"; | ||
| console.assert( | ||
| currentOutput === targetOutput, | ||
| `current output: ${currentOutput}, target output: ${targetOutput}` | ||
| ); | ||
|
|
||
| const currentOutput2 = formatAs12HourClock("23:00"); | ||
| const targetOutput2 = "11:00 pm"; | ||
| const currentOutput2 = formatAs12HourClock("23:35"); | ||
| const targetOutput2 = "11:35pm"; | ||
| console.assert( | ||
| currentOutput2 === targetOutput2, | ||
| `current output: ${currentOutput2}, target output: ${targetOutput2}` | ||
| `current output2: ${currentOutput2}, target output2: ${targetOutput2}` | ||
| ); | ||
| const currentOutput3 = formatAs12HourClock("00:00");// | ||
| const targetOutput3 = "00:00am";// expecting new test to return "00:00 am" | ||
| console.assert( | ||
| currentOutput3 === targetOutput3, | ||
| `current output3: ${currentOutput3}, target output3: ${targetOutput3}` | ||
| ); // if currentOutput3 and targetOutput3 do not match, the assertion message will be given. | ||
|
|
||
| const currentOutput4 = formatAs12HourClock("12:00");// | ||
| const targetOutput4 = "12:00pm"; // expected output for "12:00" is "12:00 pm" | ||
| console.assert( | ||
| currentOutput4 === targetOutput4, | ||
| `current output4: ${currentOutput4}, target output4: ${targetOutput4}` | ||
| );// if currentOutput and targetOutput do not match, the assertion message will be given. | ||
| const currentOutput5 = formatAs12HourClock("24:00"); | ||
| const targetOutput5 = "00:00am"; | ||
| console.assert( | ||
| currentOutput5 === targetOutput5, | ||
| `current output5: ${currentOutput5}, target output5: ${targetOutput5}` | ||
| ); // if 24:00 is entered and the output is not "00:00 am" the assertion message will be given | ||
|
|
||
| // below is test to try with minutes | ||
| const currentOutput6 = formatAs12HourClock("22:55"); | ||
| const targetOutput6 = "10:55pm"; | ||
| console.assert(currentOutput6 === targetOutput6, `current outpu6: ${currentOutput6}, target output6: ${targetOutput6}`); | ||
|
|
||
| // following test tests what happens if time passed 24:00 hours. | ||
| const currentOutput7 = formatAs12HourClock("24:25"); | ||
| const targetOutput7 = "00:25am"; | ||
| console.assert(currentOutput7 === targetOutput7, `current output7: ${currentOutput7}, target output: ${targetOutput7}`) | ||
|
|
||
|
|
||
|
|
||
|
|
||
Submodule Project-CLI-Treasure-Hunt
added at
3e6646
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.
Uh oh!
There was an error while loading. Please reload this page.