generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 245
West Midlands | 25-ITP-Sept | Ali Naru | Sprint 2 | Coursework/sprint-2 #840
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
MohammedNaru
wants to merge
15
commits into
CodeYourFuture:main
Choose a base branch
from
MohammedNaru: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
15 commits
Select commit
Hold shift + click to select a range
c9f5c3b
Fix variable redeclaration in capitalise function and update predicti…
MohammedNaru 8d94e35
Refactor comments to clarify error prediction and explanation for con…
MohammedNaru b857592
Fix parameter definition in square function and update error predicti…
MohammedNaru fc492bb
Fix multiply function to return the result and update predictions and…
MohammedNaru efcb14e
Fix sum function to return the correct result and update predictions …
MohammedNaru 15ab890
Fix getLastDigit function to use its parameter and update predictions…
MohammedNaru ab8b7e0
Implement BMI calculation in calculateBMI function and update predict…
MohammedNaru 183aa5b
Implement toUpperSnakeCase function to convert strings to UPPER_SNAKE…
MohammedNaru 13ffd18
Implement toPounds function to convert pence to pounds and add test c…
MohammedNaru c99c22e
Update comments in formatTimeDisplay function to provide answers for …
MohammedNaru 5a85a7a
Merge branch 'main' into coursework/sprint-2
MohammedNaru 954149a
completed angle type sprint work
MohammedNaru bae1417
Fix variable redeclaration in convertToPercentage function
MohammedNaru b23146f
Merge branch 'coursework/sprint-2' of https://github.com/MohammedNaru…
MohammedNaru d1cfea9
Implement BMI calculation in calculateBMI function and remove redunda…
MohammedNaru 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,37 @@ | ||
|
|
||
| // Predict and explain first BEFORE you run any code... | ||
|
|
||
| // I predict that the code will throw a ReferenceError because the variable 'num' is not defined within the function scope. | ||
|
|
||
| // this function should square any number but instead we're going to get an error | ||
|
|
||
| // | ||
|
|
||
| // =============> write your prediction of the error here | ||
|
|
||
| // I predict that the code will throw a ReferenceError because the variable 'num' is not defined within the function scope. | ||
|
|
||
| / | ||
|
|
||
| function square(3) { | ||
| return num * num; | ||
| } | ||
|
|
||
| // =============> write the error message here | ||
|
|
||
| // ReferenceError: num is not defined | ||
|
|
||
| // =============> explain this error message here | ||
|
|
||
| // This error message indicates that the variable 'num' is being used before it has been declared or defined. | ||
| // In the function 'square', the parameter is incorrectly defined as a literal value (3) instead of a variable name. | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
|
|
||
| // =============> write your new code here | ||
|
|
||
|
|
||
| function square(num) { | ||
| return num * num; | ||
| } | ||
| // Example: | ||
| console.log(square(3)); // Output: 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,13 +1,25 @@ | ||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
|
|
||
| // I predict that the code will output 'undefined' because the function sum does not return any value. | ||
|
|
||
| // this function should sum two numbers and return the result | ||
|
|
||
| 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 | ||
|
|
||
|
|
||
| // The function sum correctly returns the sum of the two numbers, so the template literal will output the correct result. | ||
|
|
||
| // 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)}`); // No change needed as the code is already correct |
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 | ||
| // Predict and explain first... | ||
| // I predict that the code will output 'undefined' because the function calculateBMI | ||
| // does not return any value yet. | ||
|
|
||
| // The BMI calculation divides an adult's weight in kilograms (kg) by their height in metres (m) squared. | ||
| // The function calculateBMI currently has no return statement, so it will return 'undefined'. | ||
| // To fix this, we need to perform the BMI calculation: | ||
| // BMI = weight / (height * height) | ||
| // Then, we round the result to one decimal place using toFixed(1). | ||
|
|
||
| // 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 | ||
| // Finally, correct the code to fix the problem | ||
| function calculateBMI(weight, height) { | ||
| const bmi = weight / (height * height); | ||
| return bmi.toFixed(1); | ||
| } | ||
|
|
||
| // 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 | ||
| module.exports = calculateBMI; | ||
|
|
||
| function calculateBMI(weight, height) { | ||
| // return the BMI of someone based off their weight and height | ||
| } | ||
| // Example: | ||
| console.log(`The BMI of someone who weighs 70kg and is 1.73m tall is ${calculateBMI(70, 1.73)}`); | ||
| // Output: The BMI of someone who weighs 70kg and is 1.73m tall is 23.4 | ||
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
54 changes: 54 additions & 0 deletions
54
Sprint-3/1-implement-and-rewrite-tests/1-get-angle-type.js
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 |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| // Implement a function getAngleType | ||
| // Build up your function case by case, writing tests as you go | ||
| // Execute this script in your terminal with: node 1-get-angle-type.js | ||
|
|
||
| function getAngleType(angle) { | ||
| if (angle === 90) { | ||
| return "Right angle"; | ||
| } else if (angle < 90) { | ||
| return "Acute angle"; | ||
| } else if (angle > 90 && angle < 180) { | ||
| return "Obtuse angle"; | ||
| } else if (angle === 180) { | ||
| return "Straight angle"; | ||
| } else if (angle > 180 && angle < 360) { | ||
| return "Reflex angle"; | ||
| } else { | ||
| return "Invalid angle"; | ||
| } | ||
| } | ||
|
|
||
| // Allow testing in other files | ||
| module.exports = getAngleType; | ||
|
|
||
| // Helper function for testing | ||
| function assertEquals(actualOutput, targetOutput) { | ||
| console.assert( | ||
| actualOutput === targetOutput, | ||
| `Expected ${actualOutput} to equal ${targetOutput}` | ||
| ); | ||
| } | ||
|
|
||
| // Test Cases | ||
|
|
||
| // Case 1: Right Angle | ||
| const right = getAngleType(90); | ||
| assertEquals(right, "Right angle"); | ||
|
|
||
| // Case 2: Acute Angle | ||
| const acute = getAngleType(45); | ||
| assertEquals(acute, "Acute angle"); | ||
|
|
||
| // Case 3: Obtuse Angle | ||
| const obtuse = getAngleType(120); | ||
| assertEquals(obtuse, "Obtuse angle"); | ||
|
|
||
| // Case 4: Straight Angle | ||
| const straight = getAngleType(180); | ||
| assertEquals(straight, "Straight angle"); | ||
|
|
||
| // Case 5: Reflex Angle | ||
| const reflex = getAngleType(270); | ||
| assertEquals(reflex, "Reflex angle"); | ||
|
|
||
| console.log("✅ All tests passed successfully!"); |
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.
What type of value do you expect your function to return? A number or a string?
Does your function return the type of value you expect?
Different types of values may appear identical in the console output, but they are represented and treated differently in the program. For example,
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.
All updated now please can you review again.
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.
Can you also answer my questions in this thread?
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 expect the function to return a number, because BMI is a numeric value that can be used in further comparisons or calculations. In my earlier implementation, using .toFixed(1) caused the function to return a string instead of a number. Although the string appears the same in the console I understand it operates differently I have now updated the function so that it returns a number by converting the result back with parseFloat().
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.
If you have updated the file, don't forget to push the changes to GitHub.