-
-
Notifications
You must be signed in to change notification settings - Fork 195
LONDON | May-2025 | Anuar Duisenbek | Module-Structuring-and-Testing-Data | Sprint-2 #559
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
base: main
Are you sure you want to change the base?
Changes from all commits
4463f02
b833e57
11cc54e
c566953
20f8a84
6376a5f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
node_modules | ||
.idea/ | ||
.DS_Store | ||
.vscode | ||
**/.DS_Store |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,29 @@ | ||
// Predict and explain first... | ||
// =============> write your prediction here | ||
// | ||
// I predict we will make mistake because str has been already declared in body of function | ||
|
||
// call the function capitalise with a string input | ||
|
||
//Uncaught SyntaxError: Identifier 'str' has already been declared | ||
|
||
// interpret the error message and figure out why an error is occurring | ||
|
||
//'str' has already been declared.Also we call function,defind it,but we don't use it. | ||
|
||
function capitalise(str) { | ||
let str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
return str; | ||
} | ||
|
||
// =============> write your explanation here | ||
|
||
//So I change : I just return str directly ,add a function call and console.log(): | ||
|
||
// =============> write your new code here | ||
|
||
function capitalise(str) { | ||
return `${str[0].toUpperCase()}${str.slice(1)}`; | ||
} | ||
|
||
console.log(capitalise("Anuar")); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
// Predict and explain first... | ||
|
||
// Predict the output of the following code: | ||
// =============> Write your prediction here | ||
|
||
//-I think here is error in function ,in getLastDigit(.......) should be num in parentheses | ||
|
||
const num = 103; | ||
|
||
function getLastDigit() { | ||
|
@@ -15,10 +16,36 @@ 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 | ||
/* | ||
So, I was almost right , | ||
the num is stick to this number "103", and actually it it should be in parenthesis. | ||
*/ | ||
|
||
// Explain why the output is the way it is | ||
// =============> write your explanation here | ||
/* | ||
// =============> write your explanation here | ||
The function `getLastDigit()` does not accept any parameters, | ||
and always returns the last digit of the constant `num = 103`. | ||
It completely ignores the numbers passed in (42, 105, 806) because it's not using them. | ||
That's why the result is always the same — "3". | ||
|
||
The last digit of 42 is 3 | ||
VM757:8 The last digit of 105 is 3 | ||
VM757:9 The last digit of 806 is 3 | ||
*/ | ||
|
||
// Finally, correct the code to fix the problem | ||
// =============> write your new code here | ||
/* | ||
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. This is great but I think you left your code commented out. |
||
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,8 @@ | |
// 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 makeAllCaps(text) { | ||
return text.toUpperCase().split(" ").join("_"); | ||
} | ||
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. This works functionally but it could be improved regarding it's time and space complexity. You are creating a new array when you call split() on a string. Imagine the input String was the size of a chapter in "lord of the rings" and you called split(" ") on the string? The array would be very large and use up memory. You could instead, use a different single method that replaces characters without using split() and join(). https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split 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. Thank you for tip. |
||
console.log(makeAllCaps("Anuar")); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,22 @@ | |
// 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 | ||
|
||
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. The function only logs the result. It should ideally return the formatted string to make it "reusable" in other areas of your program. For example: when using the function in the rest of the program you might want to pass the result into another function instead of just logging it. |
||
function toPounds(amount) { | ||
const penceStringWithoutTrailingP = amount.substring(0, amount.length - 1); | ||
|
||
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); | ||
const pounds = paddedPenceNumberString.substring( | ||
0, | ||
paddedPenceNumberString.length - 2 | ||
); | ||
|
||
const pence = paddedPenceNumberString | ||
.substring(paddedPenceNumberString.length - 2) | ||
.padEnd(2, "0"); | ||
console.log(`£${pounds}.${pence}`); | ||
} | ||
|
||
toPounds("500p"); | ||
toPounds("300p"); | ||
toPounds("1000p"); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,21 @@ | ||
// 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. | ||
|
||
function formatAs12HourClock(time) { | ||
const hours = Number(time.slice(0, 2)); | ||
if (hours === 0) { | ||
return `12:${minutes} am`; | ||
} | ||
|
||
if (hours === 12) { | ||
return `12:${minutes} pm`; | ||
} | ||
|
||
if (hours > 12) { | ||
return `${hours - 12}:00 pm`; | ||
const newHours = String(hours - 12).padStart(2, "0"); | ||
return `${newHours}:${minutes} pm`; | ||
} | ||
return `${time} am`; | ||
} | ||
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 didn't write any new tests that provide coverage for the issues you found in the code. |
||
|
Uh oh!
There was an error while loading. Please reload this page.
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.
Yes: The variable "str" is declared in the function signature as a parameter, it is then illegally redeclared in the body of the same function.