generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 266
West Midlands | 25-Sept-ITP | Georgina Rogers | Sprint 2 | Structing and Testing Data #782
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
zilinskyte
wants to merge
17
commits into
CodeYourFuture:main
Choose a base branch
from
zilinskyte: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 12 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
d17d9f0
completed
zilinskyte 8d3eb4a
code error explained and rewritten
zilinskyte 1564427
Parameter defined in function
zilinskyte 516822d
function was not returned to global scope
zilinskyte 95b56ec
function return corrected
zilinskyte bc05c26
function was calling hardcoded variable
zilinskyte 23888b9
function bmi calculator written
zilinskyte b6e2da1
returning strings in UPPER_SNAKE_CASE
zilinskyte 97e6d94
refactor toPounds function for improved input handling and output for…
zilinskyte f6b823d
time display formatting explained
zilinskyte c232401
paraeter changed name
zilinskyte 7f82d29
stretch - edge cases tested
zilinskyte fb74158
calculateBMI function to use let instead of var for variable declaration
zilinskyte 08c4269
fix: ensure BMI calculation returns a number and not a string
zilinskyte 4b1ab1f
formatted with prettier
zilinskyte fa93f1c
fix: correct minute extraction and formatting in 12-hour clock conver…
zilinskyte f46f384
files deleted
zilinskyte 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,29 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // Why will an error occur when this program runs? | ||
| // =============> write your prediction here | ||
| // constant decimalNumber is being declared twice within the same scope, which will cause a syntax error. | ||
|
|
||
| // Try playing computer with the example to work out what is going on | ||
|
|
||
| function convertToPercentage(decimalNumber) { | ||
| const decimalNumber = 0.5; | ||
| const percentage = `${decimalNumber * 100}%`; | ||
| //function convertToPercentage(decimalNumber) { | ||
| //const decimalNumber = 0.5; | ||
| //const percentage = `${decimalNumber * 100}%`; | ||
|
|
||
| return percentage; | ||
| } | ||
| //return percentage; | ||
| //} | ||
|
|
||
| console.log(decimalNumber); | ||
| //console.log(decimalNumber); | ||
|
|
||
| // =============> write your explanation here | ||
| // SyntaxError: Identifier 'decimalNumber' has already been declared | ||
| // decimalNumber is declared as a parameter of the function and then again inside the function using const. | ||
| // In JavaScript, you cannot declare the same variable name in the same scope using let or const. | ||
| // Function input is ignored if a variable with the same name is declared inside the function body. | ||
| // const decimalNumber = 0.5 will always output 50% regardless of the input value. | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
| function convertToPercentage(decimalNumber) { | ||
| const percentage = `${decimalNumber * 100}%`; | ||
| return percentage; | ||
| } | ||
| console.log(convertToPercentage(0.75)); // Example call to test the function |
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,23 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // =============> write your prediction here | ||
| // console.log is being used inside the multiply function, which does not return any value. | ||
| // This will result in undefined being printed in the template literal. | ||
|
|
||
| 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 | ||
| // Output in the terminal was: "320 | ||
| // The result of multiplying 10 and 32 is undefined" | ||
| // Console.log within the function prints the product of the calculation, but the function does not return the value to the global scope. | ||
| // Therefore within the template literal, the meaning of the multiply function call is 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
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,19 +1,20 @@ | ||
| // Below are the steps for how BMI is calculated | ||
|
|
||
| // The BMI calculation divides an adult's weight in kilograms (kg) by their height in metres (m) squared. | ||
|
|
||
| // For example, if you weigh 70kg (around 11 stone) and are 1.73m (around 5 feet 8 inches) tall, you work out your BMI by: | ||
|
|
||
| // squaring your height: 1.73 x 1.73 = 2.99 | ||
| // dividing 70 by 2.99 = 23.41 | ||
| // Your result will be displayed to 1 decimal place, for example 23.4. | ||
|
|
||
| // You will need to implement a function that calculates the BMI of someone based off their weight and height | ||
|
|
||
| // Given someone's weight in kg and height in metres | ||
| // Then when we call this function with the weight and height | ||
| // It should return their Body Mass Index to 1 decimal place | ||
|
|
||
| function calculateBMI(weight, height) { | ||
| // return the BMI of someone based off their weight and height | ||
| } | ||
| var bmi = (weight / (height * height)); | ||
| return bmi.toFixed(1); | ||
zilinskyte marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| console.log(calculateBMI(70, 1.73)); | ||
| console.log(calculateBMI(95, 1.82)); | ||
| console.log(calculateBMI(52, 1.6)); | ||
| console.log(calculateBMI(110, 1.75)); | ||
| console.log(calculateBMI(65, 1.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,6 +1,34 @@ | ||
| // In Sprint-1, there is a program written in interpret/to-pounds.js | ||
|
|
||
| // You will need to take this code and turn it into a reusable block of code. | ||
| // 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(penceString) { | ||
| penceString = String(penceString);// ensures input is treated as a string even if number is inputted | ||
| // const penceStringWithoutTrailingP = penceString.substring( | ||
| let penceStringWithoutTrailingP = penceString; | ||
| if (penceString.endsWith("p")) { | ||
| penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1); | ||
| } // This prevents the last characters from being sliced off if there is no p. | ||
|
|
||
| const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); | ||
| const pounds = paddedPenceNumberString.substring( | ||
| 0, | ||
| paddedPenceNumberString.length - 2 | ||
| ); | ||
|
|
||
| const pence = paddedPenceNumberString | ||
| .substring(paddedPenceNumberString.length - 2) | ||
| .padEnd(2, "0"); | ||
|
|
||
| return`£${pounds}.${pence}`; | ||
| } | ||
zilinskyte marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| console.log(toPounds("481p")); | ||
| console.log(toPounds("50p")); | ||
| console.log(toPounds("5p")); | ||
| console.log(toPounds("0p")); | ||
| console.log(toPounds("12345p")); | ||
| console.log(toPounds("9")); // edge case: missing 'p' at the end, returns 0 rather than error because last character is sliced off | ||
| // Can be fixed by changing line 8 | ||
| console.log(toPounds("abc")); // Works but returns nonsense value | ||
| console.log(toPounds(123)); // Works with number input because of line 7 converting to string | ||
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.
Uh oh!
There was an error while loading. Please reload this page.