Skip to content

Manchester | ITP-May-2026 | Szidonia Bodo | Sprint 1 | Coursework Exercises #1417

Open
bodoszidi wants to merge 15 commits into
CodeYourFuture:mainfrom
bodoszidi:Sprint-1
Open

Manchester | ITP-May-2026 | Szidonia Bodo | Sprint 1 | Coursework Exercises #1417
bodoszidi wants to merge 15 commits into
CodeYourFuture:mainfrom
bodoszidi:Sprint-1

Conversation

@bodoszidi

Copy link
Copy Markdown

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Changelist

to explain the code line by line

Questions

@bodoszidi bodoszidi added 📅 Sprint 1 Assigned during Sprint 1 of this module Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Module-Structuring-And-Testing-Data The name of the module. labels Jun 29, 2026
Comment on lines +8 to +9
// Line 3, we reassign a new value to the count variable,
// the new value is count plus 1. No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Operation like count = count + 1 is very common in programming, and there is a programming term describing such operation.

Could you find out what one-word programming term describes the operation on line 3?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The term would be incrementing ++ or if it's the opposite, decrementing --

Comment on lines +19 to +21
const dir = filePath.slice(1, 16);
const ext = filePath.slice(-4);
console.log(`The base part of ${dir} is ${ext}`);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you make these statements to work for any valid path? For example, they could still work correctly if we changed line 12 to

const filePath = "/Users/jacknguyen448/cyf/Module-2/Sprint-1/package.json";

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes, if we use the already created slash index and create a new dot index, the file path length can change at any point. The code below will find the "/" and the "." and we no longer need to count the length of our filepath:
const lastDotIndex = filePath.lastIndexOf(".")
const dir = filePath.slice(0, lastSlashIndex);
const ext = filePath.slice(lastDotIndex + 1);


// It will help to think about the order in which expressions are evaluated
// Try logging the value of num and running the program several times to build an idea of what the program is doing
// num = Math.floor which will remove all the numbers after the decimal point

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you look up the differences among Math.round(), Math.trunc(), Math.floor(), Math.ceil()?
All of these functions remove the decimal part of a number, but in different manner.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Math.round() - rounds the number to the nearest -> .1 - .4 ⬇️ & .5 - .9 ⬆️
Math.trunc() - removes all the numbers after the decimal point - without rounding the number
Math.floor() - rounds down and returns the largest integer less than or equal to a given number. rounding the number down ⬇️
Math.ceil() - rounds the given number to the smallest integer greater than or equal to a given number. rounding the number ⬆️

The above answer I gave was actually correct for Math.trunc() - Math.floor() will actually round the number to the largest integer less than or equal to the given number - if we have a negative integer, we would get the lower number back, as Math.floor(-3.03) would return -4

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Your approach is correct, and you are right that either Math.trunc() or Math.floor() works. I just want you to be aware of different math functions.

Comment on lines +14 to +16
// (Math.random that will generate a random decimal number
// which will be times with the value of maximum - minimum + 1 + minimum )
// which is 100 * the Math.random generated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Math.random() returns a random number within a range.

Could you describe what each of these expressions does, and the range of the numbers it may produce?

  1. Math.random()
  2. Math.random() * (maximum - minimum + 1)
  3. Math.floor(Math.random() * (maximum - minimum + 1))
  4. Math.floor(Math.random() * (maximum - minimum + 1)) + minimum

Note: To describe a range of numbers, we could use the math interval notation:

  • [, ] => inclusion
  • (, ) => exclusion

For example, [1, 10) means, all numbers between 1 and 10, including 1 but excluding 10.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

  1. Math.random() - generates a decimal number between [0, 1] - but excluding 1
  2. Math.random() * (maximum - minimum + 1) - the generated decimal number * 100 - [0, 100]
  3. Math.floor(Math.random() * (maximum - minimum + 1)) - the generated decimal number * 100 - Math.floor() round the number to the nearest lower number - [0, 99]
  4. Math.floor(Math.random() * (maximum - minimum + 1)) + minimum
  • (the generated decimal * 100) +1 - Math.floor() round the number to the nearest lower number [1, 100]

Comment on lines +1 to 2
const cardNumber = "4533787178994213";
const last4Digits = cardNumber.slice(-4);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suppose you were not allowed to modify the statement const cardNumber = 4533787178994213;
(that is, keep the variable's value unchanged).
How would you modify the code (through type conversion) to still being able to use .slice(-4) to extract the last 4 digits from the given number.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

If I can't modify the number would need to be converted to a string:
const cardNumber = 4533787178994213
const cardNumberString = cardNumber.toString()
const last4Digit = cardNumberString.slice(-4)

or

const cardNumber = 4533787178994213
const last4Digit = cardNumber.toString().slice(-4)

// there is 5 calls: 2* Number() 2* .replaceAll() AND 1* .log()

// b) Run the code and identify the line where the error is coming from - why is this error occurring? How can you fix this problem?
// line 5 missing a comma: .replaceAll("," "")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We could more precisely describe "A comma is missing between "," and "" in the function call" as:
A comma is missing between the ___________s.

What is this programming term that refers to the values passed to a function? It begins with an 'a'.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The comma is missing between the two arguments "," and ""

// to calculate the movie length into minutes

// e) What do you think the variable result represents? Can you think of a better name for this variable?
// the result represent the movie length - hours minutes and second in a string - movieTime

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The name movieTime does not quite indicate the value stored in the variable
is a formatted string in the form "2:12:02".

Could you suggest a more descriptive name?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

movieLengthFormatted - would represent the value in a clearer way, also would indicate to the given variable movieLength - but in a formatted output

What is the return value of `prompt`?
What effect does calling the `prompt` function have? - the prompt will also display a message usually question - however this time you will have an empty field to enter the value or answer - a cancel and a OK button

What is the return value of `prompt`? - whatever the user inputs into the empty field No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What if the a enters something and then click "Cancel" instead of "OK?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

If the user cancels the prompt, the returned value will be null.

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Jul 2, 2026
@bodoszidi bodoszidi added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Jul 2, 2026
@cjyuan

cjyuan commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Well done addressing all comments, and they are all correct.

@cjyuan cjyuan added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Jul 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Complete Volunteer to add when work is complete and all review comments have been addressed. Module-Structuring-And-Testing-Data The name of the module. 📅 Sprint 1 Assigned during Sprint 1 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants