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

NW6 | HAYTHEM MOHAMMED | Module-JS1 | WEEK1 #129

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

Conversation

haythem-f
Copy link

@haythem-f haythem-f commented Nov 10, 2023

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.

Choose a reason for hiding this comment

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

Great work Haytham. I just wondered why you used the function Math.trunc instead of Math.floor. could you please tell me what's the difference between them :)

Copy link
Author

Choose a reason for hiding this comment

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

Thanks, Fidaa for your feedback. And regarding your query about using Math.trunc instead of Math.floor! I would like to clarify that in this case, they are doing the same job. but in different cases, they return different values.
Math.trunc always removes any fractional digits. but Math.floor rounds down and returns the largest integer less than or equal to the given number. for example if we us both Math.trunc and Math.floor with "1.1" they will return the same result. but if we used them with "-1.1" the result will be different.

// It will help to think about the order in which expressions are evaluated
// Try logging the value of num several times to build an idea of what the program is doing
//The Program is to return a random integer between 1 and 100

console.log(num);

Choose a reason for hiding this comment

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

You have explained this very well. I found this a bit confusing to do myself but your explanation makes sense a lot. Well done!

What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean?
// the console object is calling the functions log and assert. // The "." is to call a function.

Choose a reason for hiding this comment

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

This is a really good explanation. I did not know this. I think the whole group can benefit from this explanation.

@@ -27,3 +19,5 @@ console.log(`£${pounds}.${pence}`);
// To begin, we can start with

// 1. const penceString = "399p": initialises a string variable with the value "399p"

// Substring, padStart and padEnd : to return part of string.

Choose a reason for hiding this comment

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

This is also very easy to understand and simple explanation. Good work!

Copy link

@HadikaMalik HadikaMalik left a comment

Choose a reason for hiding this comment

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

Your explanations are very clear and simple and easy to understand. Good work, well done!

const cardNumber = 4533787178994213;
const last4Digits = cardNumber.slice(-4);
const cardNumber = "4533787178994213";
const last4Digits = cardNumber.slice(12,16);
Copy link
Member

Choose a reason for hiding this comment

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

You can keep .slice(-4), that will still work. The only issue here was the string 🙂

@@ -15,4 +15,7 @@ const base = filePath.slice(lastSlashIndex + 1);
console.log(`The base part of ${filePath} is ${base}`);

// Create a variable to store the dir part of the filePath variable
const DirPart = filePath.slice(1, 45);
Copy link
Member

Choose a reason for hiding this comment

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

This solution works great for the example, but think about how we could extend the solution to work for different file paths (where we don't already know the length)


// b) How many function calls are there?
// no function calls
Copy link
Member

Choose a reason for hiding this comment

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

console.log(..) could be considered a function call 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants