-
-
Notifications
You must be signed in to change notification settings - Fork 301
ITP_J25_LDN| EYUEL_ABRAHAM | Module-Structuring-and-Testing-Data Coursework/sprint 2 | WEEK-2 #258
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
Conversation
|
|
||
| // =============> write your explanation here | ||
|
|
||
| // trying to redeclare the variable called decimalNumber twice in the function. |
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.
also- the code was not invoking the convertToPercentage function which you corrected
Sprint-2/2-mandatory-debug/1.js
Outdated
| // console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); | ||
|
|
||
| // =============> write your explanation here | ||
| // =============> write your explanation here: The sum of 10 and 32 is undefined because a+b is written under the return statement. |
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.
it is actually because that is what the function returns. return; will always return undefined. It is the same as writing return undefined
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.
Noted. Thanks.
| // console.log(`The last digit of 806 is ${getLastDigit(806)}`); | ||
|
|
||
| function getLastDigit() { | ||
| // Now run the code and compare the output to your prediction |
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.
You've corrected the mistake but your explanation isn't quite right. The problem was the number wasn't passed into the function as a parameter
| // 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 | ||
|
|
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.
fun fact- this is sometimes called screaming snake case!
| let pounds = paddedPenceNumberString.substring(0,paddedPenceNumberString.length - 2); | ||
| const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"); | ||
| return `£${pounds}.${pence}` | ||
| } |
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.
Great job so far !
try and test this one here:
function changeToPounds(penceString){
return £${(parseInt(penceString) / 100).toFixed(2)};
}
This is a robuster method to convert to pounds, and easier to understand . You don't need to worry about where de letter p will appear in the string, when using parseInt , it removes all letters elements from the value and takes just the numbers.
And then , just divide it to 100 to transform pence in pounds .
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.
Done. This method is very simple and amazing. Thankyou!
fernandamelov
left a comment
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.
Great job so far !
try and test this one here for 3-mandatory-implement/3-to-pounds.js:
function changeToPounds(penceString){
return £${(parseInt(penceString) / 100).toFixed(2)};
}
This is a robuster method to convert to pounds, and easier to understand . You don't need to worry about where de letter p will appear in the string, when using parseInt , it removes all letters elements from the value and takes just the numbers.
And then , just divide it to 100 to transform pence in pounds .
| // You should call this function a number of times to check it works for different inputs | ||
|
|
||
| function changeToPounds(penceString){ | ||
| let penceStringWithoutTrailingP = penceString.substring(0,penceString.length - 1); |
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.
string.slice() is a little easier for this
let penceStringWithoutTrailingP = penceString.slice(0, -1);
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.
Okay. Thankyou!
| // a) When formatTimeDisplay is called how many times will pad be called? | ||
| // =============> write your answer here | ||
|
|
||
| // three times |
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.
is there a way you can check this?
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.
We can use a global variable, which is increased each time the function is called.(got it from stackoverflow).
var myFuncCalls = 0;
function pad(num) {
myFuncCalls++;
console.log( "I have been called " + myFuncCalls + " times" );
return num.toString().padStart(2, "0");
}
| // three times | ||
| // Call formatTimeDisplay with an input of 61, now answer the following: | ||
|
|
||
| // b) What is the value assigned to num when pad is called for the first time? |
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.
this depends on the number passed in at the start. If it's big enough it will be more than 0
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.
Noted, Thankyou for the review.
|
|
||
| function getAngleType(angle) { | ||
| if (angle === 90) return "Right angle"; | ||
| if (angle === 90) return "Right angle"; |
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.
none of these if statements need to be else if or else because you are returning a value from the function. Whenever you return something from a function, the execution stops so none of the code below is executed.
Also, you know that an angle is < 90 because the code carried on past that if statment so you only need to do:
if(angle < 90) return "Acute angle";
if(angle < 180) return "Obtuse angle";
if(angle < 360) return "Reflex angle";
etc
Feel free to message me if this doesn't make sense
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.
This commit and the one after this were not supposed to be on this Pull request as they are from sprint three they are here by accident. I'll have to redo them with other the sprint 3 question on a new branch and a new PR for sprint 3.
| else if (angle === 180) return "Straight angle" | ||
| else if (angle > 180 && angle < 360) return "Reflex angle" | ||
| else if(angle === 360) return "Full angle" | ||
| else return "please insert a valid angle (0-356)" |
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.
angles up to 360 should be valid
|
|
||
| function isProperFraction(numerator, denominator) { | ||
| if (numerator < denominator) return true; | ||
| if (Math.abs(numerator) < Math.abs(denominator) && numerator !=0 && denominator != 0) return true; |
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.
Careful. the Math.abs() method just takes any negative number and turns it into a positive which would break this function in certain scenarios.
For example: console.log(isProperFraction(-5, 3)); would incorrectly return false when it is a proper fraction.
Do you know how you could fix this bug? Feel free to message me if you need a hand
BenSymons
left a comment
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.
A few suggestions and some small mistakes here and there but for the most part, well done!
…tion from review on my work.
|
Well done you can close this PR now |
Learners, PR Template
Self checklist
Changelist
Briefly explain your PR.
Completed the exercises given for sprint two.
Questions
Ask any questions you have for your reviewer.