generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 197
LONDON | ITP-MAY-25 | SURAFEL WORKNEH | Module-Structuring-and-Testing-Data | acoursework/sprint 2 #667
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
SuWebOnes
wants to merge
18
commits into
CodeYourFuture:main
Choose a base branch
from
SuWebOnes: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
LONDON | ITP-MAY-25 | SURAFEL WORKNEH | Module-Structuring-and-Testing-Data | acoursework/sprint 2 #667
Changes from 15 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
6e9aa77
update: Fix variable redeclaration error in capitalise function and u…
SuWebOnes 2302130
update: convertToPercentage function to fix redeclaration error and …
SuWebOnes 1b1b8c9
update: Predict and explain code, then fix square function to correct…
SuWebOnes 58aa840
update: Fix multiply function to return the product of two numbers an…
SuWebOnes 6bc6fa9
update: Predict and explain the output, Fix sum function to correctly…
SuWebOnes 889a9a9
update: predict the output, explain the cause of the problem, then Fi…
SuWebOnes 5d354cd
update: Add output explanation for getLastDigit function to clarify w…
SuWebOnes 3c47903
update: Implement calculateBMI function to compute Body Mass Index ba…
SuWebOnes 32c94e5
update: Add toUpperSnakeCase function to convert strings to UPPER_SNA…
SuWebOnes 1c4a2db
update: Implement toPounds function to convert pence strings to forma…
SuWebOnes a349242
fix: Understanding and explain the behavior of formatTimeDisplay() an…
SuWebOnes 0d71e05
update: tests formatAs12HourClock function for as many different grou…
SuWebOnes 84e5b3c
update: padding for hour
SuWebOnes 99480d3
Merge branch 'CodeYourFuture:main' into acoursework/sprint-2
SuWebOnes 9190a03
trainig commite
SuWebOnes 2d292bb
update: fix the return type to number
SuWebOnes 98b0e74
update: testing alternative way by apply convert to upre case, then s…
SuWebOnes f9da062
Merge branch 'main' into acoursework/sprint-2
SuWebOnes 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,26 @@ | ||
|
||
// Predict and explain first BEFORE you run any code... | ||
|
||
// the will be an error | ||
// this function should square any number but instead we're going to get an error | ||
|
||
// Why will an error occur when this program runs? | ||
//because the function parameter is incorrectly defined by real number instead of a variable name | ||
|
||
// =============> write your prediction of the error here | ||
|
||
function square(3) { | ||
return num * num; | ||
} | ||
// function square(3) { | ||
// return num * num; | ||
// } | ||
|
||
// =============> write the error message here | ||
|
||
//syntaxError: Unexpected number | ||
// =============> explain this error message here | ||
|
||
// The error occurs because the function parameter is defined as a number (3) instead of a variable name. | ||
// In JavaScript, function parameters must be variable names, not literal values. JavaScript is expecting a parameter name in the parentheses, not a value. | ||
// Finally, correct the code to fix the problem | ||
|
||
// =============> write your new code here | ||
|
||
|
||
function square(num) { | ||
return num * num; | ||
} | ||
console.log(square(3)); // This will not work because 'num' is not defined outside 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,30 @@ | ||
// Predict and explain first... | ||
|
||
// The code below is intended to multiply two numbers and log the result. | ||
// However, it currently does not return the result correctly. | ||
// The function `multiply` is defined to take two parameters `a` and `b`. | ||
// It logs the product of `a` and `b` but does not return it. | ||
// The console.log statement outside the function attempts to log the result of calling `multiply(10, 32)`. | ||
// The expected output is "The result of multiplying 10 and 32 is 320". | ||
// However, since `multiply` does not return a value, the output will be "The result of multiplying 10 and 32 is undefined". | ||
// =============> write your prediction here | ||
|
||
function multiply(a, b) { | ||
console.log(a * b); | ||
// This function multiplies two numbers and logs the result | ||
// but does not return it. | ||
// It should return the product instead of just logging it. | ||
// The current implementation will not return the product. | ||
//console.log(a * b); | ||
// This line should be changed to return the product | ||
return a * b; // Corrected to return the product | ||
} | ||
|
||
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); | ||
|
||
// =============> write your explanation here | ||
// // The code is intended to multiply two numbers and log the result. | ||
// However, it currently does not return the result correctly. | ||
// The expected output is "The result of multiplying 10 and 32 is 320". | ||
// The current output will be "The result of multiplying 10 and 32 is undefined". | ||
|
||
// 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,13 +1,20 @@ | ||
// Predict and explain first... | ||
// =============> write your prediction here | ||
// The sum of 10 and 32 is undefined | ||
|
||
function sum(a, b) { | ||
return; | ||
a + b; | ||
} | ||
// function sum(a, b) { | ||
// return; | ||
// a + b; | ||
// } | ||
|
||
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); | ||
// console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); | ||
|
||
// =============> write your explanation here | ||
// The function called `sum` is defined to take two parameters `a` and `b`, but it does not return the result of adding them together. | ||
// Instead, it has a `return` statement which exits the function without returning any value. | ||
// Finally, correct the code to fix the problem | ||
// =============> write your new code here | ||
function sum(a, b) { | ||
return a + b; | ||
} | ||
console.log(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,37 @@ | ||
// Predict and explain first... | ||
// This code is intended to find the last digit of a number, but it has a bug. | ||
|
||
// Predict the output of the following code: | ||
// Predict the output of the following code is '3' for the input 103. since the last digit of 103 is 3 and it is a global variable, so regardless of the input, it will always return the last digit of the global variable `num` which is 103. | ||
// =============> Write your prediction here | ||
|
||
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 | ||
// The last digit of 42 is 3 | ||
// The last digit of 105 is 3 | ||
// The last digit of 806 is 3 | ||
|
||
// =============> write the output here | ||
// The output is always '3' | ||
// Explain why the output is the way it is | ||
// =============> write your explanation here | ||
// The output is always '3' because the function `getLastDigit` is using a global variable `num` which is set to 103 | ||
// Finally, correct the code to fix the problem | ||
// =============> write your new code here | ||
|
||
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)}`); | ||
// 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,36 @@ | |
// You will need to come up with an appropriate name for the function | ||
// Use the MDN string documentation to help you find a solution | ||
// This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase | ||
|
||
function toUpperSnakeCase(string) { | ||
//split the string into an array of words | ||
const wordsArray = string.split(" "); | ||
// Convert each word to uppercase | ||
const upperWordsArray = wordsArray.map((word) => word.toUpperCase()); | ||
// Join the array back into a string with underscores | ||
const toUpperSnakeCase = upperWordsArray.join("_"); | ||
// Return the string in UPPER_SNAKE_CASE | ||
return toUpperSnakeCase; | ||
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. You could also apply |
||
} | ||
// Example usage for this function | ||
// let string = "hello there"; | ||
|
||
// console.log(`The string in UPPER_SNAKE_CASE is: ${toUpperSnakeCase(string)}`); | ||
|
||
console.log( | ||
`The string in UPPER_SNAKE_CASE for 'hello there' is: ${toUpperSnakeCase( | ||
"hello there" | ||
)}` | ||
); | ||
|
||
console.log( | ||
`The string in UPPER_SNAKE_CASE for 'lord of the rings' is: ${toUpperSnakeCase( | ||
"lord of the rings" | ||
)}` | ||
); | ||
|
||
console.log( | ||
`The string in UPPER_SNAKE_CASE for 'example usage for this function' is: ${toUpperSnakeCase( | ||
"example usage for this 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
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
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 the function to return? A number or a string?
Does your function return the type of value you expect it to return?
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.
number including decimals
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.
fixed to return type to numbers