Skip to content
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

WM4 | Fatima Safana |Module 2/Sprint1 Exercises | Week4 #213

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

Fatimasfn
Copy link

Learners, PR Template

Self checklist

  • I have committed my files one by one, on purpose, and for a reason
  • I have titled my PR with COHORT_NAME | FIRST_NAME LAST_NAME | REPO_NAME | WEEK
  • I have tested my changes
  • My changes follow the style guide
  • My changes meet the requirements of this task

Changelist

Briefly explain your PR.

Questions

Ask any questions you have for your reviewer.

@Fatimasfn Fatimasfn added the Needs Review Participant to add when requesting review label Dec 2, 2024
@cjyuan cjyuan self-requested a review December 2, 2024 20:09
Copy link

@cjyuan cjyuan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code is good. I just left some suggestions and questions to challenge you in the code.

@@ -1,9 +1,13 @@
const cardNumber = 4533787178994213;
const cardNumber = "4533787178994213";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you cannot modify this statement const cardNumber = 4533787178994213;
(that is, keep the variable's value unchanged),
how would you modify the code so that it can still extract the last 4 digits from its value.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the type of variable needs to string for .slice() method to work.

const twelveHourClockTime = "20:53";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you also noticed the variable names do not quite match the values assigned to the variable?

console.log(wholeNumberPart)

let decimalPart = num - Math.floor(num);
console.log(decimalPart);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you run the program, you may notice that console.log() outputs the value of decimalPart
with more than 4 decimal places (which is normal because of floating point arithmetic).

If you were asked to print the value of decimalPart to exactly 4 decimal places,
how would you modify the code?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let decimalPart = (num - Math.floor(num)).toFixed(4);
console.log(decimalPart);

console.log(`The base part of ${filePath} is ${base}`);

// Create a variable to store the dir part of the filePath variable
// Create a variable to store the ext part of the variable

const dirPart = filePath.substring(45, -1);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your code should be written to to work for any valid value of filePath.
For example, "/path1/path2/package.json".

const dirPart = filePath.substring(45, -1);
console.log(`The directory path of ${dirPart}`);

const extPart = dirPart + "ext.txt";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "ext part" refers to the file extension of the file represented by the file path, which is the string after the dot in the base (including the dot).

So the file extension of "package.json" would be ".json".


console.log(num);

// The program creates a random whole number between 1 and 100, max and min inclusive.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This exercise was expecting you to break down
the expression Math.floor(Math.random() * (maximum - minimum + 1)) + minimum, and explain
why such expression can correctly produce a random integer in the range [1, 100].

Also, to test your understanding, how would you write an expression
(without using any variable in the expression) that yields a random
integer between -5 and 3 (including -5 and 3)?

// 3. initializes a variable that removes the "p" at the end, it uses method .substring
// which returns the part of the string corresponding to the index and end index
//-1 excluding the p
//9. uses the method padstart to add "0" to the start of string penceStringWithoutTrailingP,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After line 9, what would paddedPenceNumberString be if penceString was "1234p" initially?
After line 9, what would paddedPenceNumberString be if penceString was "4p" initially?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will return 1234
It will return 004

// this effectively multiplies any value input as penceStringWithoutTrailingP by 100
//12. uses the substring method to return the first value of the string, this is to get
// the pound. it also used length -2 to make sure its in a valid range so the program
// can go through the steps with any value input.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by "first value of the string"?
length - 2 is a valid range but "making sure its in a valid range" is not quite the reason why length - 2
is used in the code.

//12. uses the substring method to return the first value of the string, this is to get
// the pound. it also used length -2 to make sure its in a valid range so the program
// can go through the steps with any value input.
//18.the code gets the last two digits from the paddedPenceNumberString and ensures that the result
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we expect this program to work as intended even if we deleted .padEnd(2, "0") from the code?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, it will not work for single digit or double digits input

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, can you find a value of penceString to show that the function won't work properly without .padEnd(2, "0")?

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review and removed Needs Review Participant to add when requesting review labels Dec 2, 2024
@Fatimasfn
Copy link
Author

Thank you @cjyuan for reviewing my code, I appreciate the feedback.

@Fatimasfn Fatimasfn added the Complete Participant to add when work is complete and review comments have been addressed label Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Complete Participant to add when work is complete and review comments have been addressed Reviewed Volunteer to add when completing a review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants