Skip to content

Comments

Birmingham| ITP-Jan | Ahmad Roman Sanaye| Sprint 1| Structuring and Testing Data#958

Open
RomanSanaye wants to merge 6 commits intoCodeYourFuture:mainfrom
RomanSanaye:coursework/sprint-1
Open

Birmingham| ITP-Jan | Ahmad Roman Sanaye| Sprint 1| Structuring and Testing Data#958
RomanSanaye wants to merge 6 commits intoCodeYourFuture:mainfrom
RomanSanaye:coursework/sprint-1

Conversation

@RomanSanaye
Copy link

@RomanSanaye RomanSanaye commented Feb 11, 2026

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 using Node
  • My changes follow the style guide

Changelist

  • Completed Sprint 1 exercises
  • Ran all files using Node to identify and understand errors
  • Added explanations and comments to interpret the code
  • Explored stretch tasks to reinforce understanding

@RomanSanaye RomanSanaye added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Feb 11, 2026
@github-actions

This comment has been minimized.

@github-actions github-actions bot removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Feb 11, 2026
@github-actions

This comment has been minimized.

@RomanSanaye RomanSanaye added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Feb 12, 2026
@hkavalikas hkavalikas self-requested a review February 19, 2026 07:23
@hkavalikas hkavalikas added Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Feb 19, 2026
const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt";
const lastSlashIndex = filePath.lastIndexOf("/");
const base = filePath.slice(lastSlashIndex + 1);
const base = filePath.slice(-8);

Choose a reason for hiding this comment

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

We have updated the provided lastSlashIndex with a magic number like -8, what would happen if we now renamed our file.txt to best-file-ever.txt? Would this solution still work?

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for the feedback! @hkavalikas 🙏
I removed the magic number and updated the logic to use lastIndexOf("/") to dynamically locate the last slash, combined with substring() to safely extract the file name.
With this approach, the code will continue to work correctly even if the file name changes .

// Try logging the value of num and running the program several times to build an idea of what the program is doing

// num is a variable that will be assigned an integer number after the operators are done.
// Math.floor() rounds a decimal to its nearest number to make it an integer. ex = 1.2 => 1.

Choose a reason for hiding this comment

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

What would happen if we did Math.floor(1.9);?

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the feedback!
Math.floor() always rounds a number down to the nearest integer by removing the decimal part. Here it will return 1.

Choose a reason for hiding this comment

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

What does the + minimum do here?

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for the feedback!
The + minimum shifts the random value into the desired range.
Without it, the formula would generate numbers between 0 and (maximum - minimum).
By adding minimum, the result is shifted to fall within the range of minimum to maximum (for example, 1 – 100).

Comment on lines +5 to +8
//solution: Simply comment the lines.
// 1- single line comment like: // example ...
// 2- multiline comment like : /* a, b, c */
// comments are for instruction of guidance of who will read our codes, but the computer wont read them. No newline at end of file

Choose a reason for hiding this comment

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

Explanation is spot on, let's take it a step further and execute it! I want to run this file without a syntax error. Can we make it possible?

Copy link
Author

@RomanSanaye RomanSanaye Feb 19, 2026

Choose a reason for hiding this comment

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

Thank you for the feedback!
I have updated the file by commenting out the instructional lines so they are no longer executed by the interpreter.

age = age + 1;
//age = age + 1;

// we can't do that with const variable, because JS locks the reference.

Choose a reason for hiding this comment

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

Also spot on, let's take the approach and fix the broken code over declaring additional variables.

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for the feedback!
I have updated the code by fixing the original variable instead of introducing additional variables.


// we have variable declarations at lines 1, 2, 7 and 8.
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
// the purpose of that expression is to turn into number the string and replace all commas with an empty space. No newline at end of file

Choose a reason for hiding this comment

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

This comment is mostly correct, but I do want to highlight the second part of your answer. Is there anything we can do to improve it slightly?

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for the feedback!
We improved the explanation: the expression Number(carPrice.replaceAll(",", "")) first removes all commas from the string (for example, "1,000" becomes "1000"), and then converts the cleaned string into a number (1000).

// movieLength % 60 expression represents the remaining seconds.
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?

// that expression turns the seconds into minutes.

Choose a reason for hiding this comment

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

You are right, but let's try to break it down step by step, how is the expression doing that?

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for the feedback!
I broke it down step by step:

movieLength % 60 gives the leftover seconds that don’t fit into a full minute.

movieLength - remainingSeconds removes those leftover seconds.

Dividing by 60 converts the remaining seconds into total minutes.

This shows clearly how the expression turns the total seconds into minutes while keeping track of leftover seconds.

// e) What do you think the variable result represents? Can you think of a better name for this variable?

// the result variable represents the movie length in Hour, minutes and seconds.
// a better name can be "movieLength".

Choose a reason for hiding this comment

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

Can you see any problem if we were to name it movieLength?

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for the feedback!
If we name the final result variable movieLength, it could be confusing because we already have a variable movieLength holding the total seconds.
Using a different name, like movieDuration, makes the code clearer and avoids accidentally overwriting the original value.

// the result variable represents the movie length in Hour, minutes and seconds.
// a better name can be "movieLength".
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
// as I changed the value of the movieLength the results has changed too.It means this code works with any value. No newline at end of file

Choose a reason for hiding this comment

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

There are a few cases that might break this. Can you spot and mention a few?

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for the feedback!
Some cases that could break the code include:

Negative numbers (a movie cannot have negative seconds)

Decimal numbers (like 8777.22)

Invalid inputs (like strings, null, or undefined)

Handling these cases ensures the program works safely and produces correct results.

Choose a reason for hiding this comment

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

Optional: There are a few questions before the "Answer the following questions" too, if you want to add an answer to those too for completeness.

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for the feedback!
I have added answers to the optional questions for completeness.

@hkavalikas hkavalikas added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels Feb 19, 2026
…ll, random min, and safe movie length calculations with edge case handling
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Reviewed Volunteer to add when completing a review with trainee action still to take.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants