Skip to content

London | 26-ITP-Sep | Rawan Almutairi | Sprint 2 | JavaScript exercises - #1628

Open
Rawan0-0 wants to merge 1 commit into
CodeYourFuture:mainfrom
Rawan0-0:sprint-2
Open

Rawan0-0 wants to merge 1 commit into
CodeYourFuture:mainfrom
Rawan0-0:sprint-2

Conversation

@Rawan0-0

@Rawan0-0 Rawan0-0 commented Sep 29, 2026 •

Copy link
Copy Markdown

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

Task code

CYF-1039

Changelist

Sprint 2 work

Questions

No questions

@netlify

netlify Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for cyf-onboarding-module ready!

Name Link
🔨 Latest commit f6c55f9
🔍 Latest deploy log https://app.netlify.com/projects/cyf-onboarding-module/deploys/6abb00bcb2c433000869b018
😎 Deploy Preview https://deploy-preview-1628--cyf-onboarding-module.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
2 paths audited
Performance: 100 (no change from production)
Accessibility: 100 (no change from production)
Best Practices: 100 (no change from production)
SEO: 86 (no change from production)
PWA: -
View the detailed breakdown and full score reports
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions

This comment has been minimized.

@Rawan0-0 Rawan0-0 added 📅 Sprint 2 Assigned during Sprint 2 of this module Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Sep 29, 2026
@github-actions

This comment has been minimized.

1 similar comment
@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 Sep 29, 2026

@iscmiguelsamaniego iscmiguelsamaniego left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fantastic work! Your technical grasp, attention to edge cases (like octal numbers), and step-by-step code breakdowns are spot-on.

Keep up this meticulous approach—you are making brilliant progress!

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Great job! You correctly identified how the variable is initialized and reassigned.

Quick question: How would you specifically describe the role of the = sign in that second line?

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.

//Line two we see the variable count using the = sign to assign a new value whcih is count previous value + 1
//the equal sign in line two is assigned operator that stores the new value to the variable

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Great job! This is a very clean and clever solution using template literals and bracket notation.

Quick question: Is there another built-in string method besides bracket notation you could use to get the first character?

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.

string.prototype.replace()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Spot-on implementation for extracting dir and ext! To polish your code, you can make the comments a bit more direct and concise.

Quick question: When using filePath.slice(0, lastSlashIndex) for dir, why do we include 0 as the starting index, and what happens if you omit it?

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 we omit the first index, the string won't break but will go to the wrong location; in the case of omitting the 0 index, it will delete anything before the last index ''/'

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Clear breakdown of the math logic!

Just remember the order: Math.random() runs first to generate a decimal, then the math scales it, and finally Math.floor() rounds it down.

Quick question: What purpose does the + 1 serve inside (maximum - minimum + 1)?

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.

I had to search for this one to understand it. Math.random() generates a decimal that ranges between the values 0 and 0.99999, so when we try to scale it up Math.random() will generate values between 0 and 8.9999, so it doesn't include 9. This becomes an issue when we use Math.floor as it will round it to the nearest whole number, and because it doesn't include the number 9, it will round down from 0 to 8.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Spot-on distinction between const and let for handling variable updates.

Quick question: Is there a shorthand assignment operator you could use instead of writing age = age + 1?

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, +=

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Not quite a ReferenceError here—cardNumber is actually declared, but because it's a number rather than a string, JavaScript throws a TypeError because .slice() isn't a valid method for numbers.

Quick question: What method can you call on cardNumber to convert it into a string first so .slice(-4) will work?

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.

toString()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Spot-on explanation! Variable names cannot start with numbers.

Quick question: While starting with a capital letter works syntactically, what is the standard JavaScript naming convention (case style) usually used for variables made of multiple words like this?

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.

camelCase

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Spot-on answers! Your breakdown of line 5's syntax error, reassignments, and the purpose of replaceAll() is completely accurate.

Quick question: Why is replaceAll() a better choice here than a standard replace() method?

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.

replaceAll includes all the specified characters and changes them, unlike replace(), which searches for the character but stops once it is found.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Spot-on analysis! Your observation about leading zeros triggering an octal syntax error is a brilliant and advanced catch.

Quick question: If remainingSeconds is 5, the output currently shows ...:5 instead of ...:05. How might you ensure single-digit numbers always display with two digits?

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.

Since the digit zero is before the 5. We create a numerical string, then convert the string to a numerical value or add the zero digit as a string before the number or we modify the function to include strings so we can manipulate the numbers.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Great step-by-step breakdown! You clearly traced how substring, padStart, and padEnd work together to parse and format the price string correctly.

Quick question: Why is padStart(3, "0") particularly important if someone inputs a smaller value like "9p" instead of "399p"?

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.

It specify the starting values so we don't have random numbers that could cause a bug in the program. We restrict it.

@github-actions

This comment has been minimized.

5 similar comments
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@Rawan0-0 Rawan0-0 added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed 📅 Sprint 2 Assigned during Sprint 2 of this module labels Sep 30, 2026
@github-actions

This comment has been minimized.

2 similar comments
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@Rawan0-0

Copy link
Copy Markdown
Author

Fantastic work! Your technical grasp, attention to edge cases (like octal numbers), and step-by-step code breakdowns are spot-on.

Keep up this meticulous approach—you are making brilliant progress!

Thank you so much for this wonderful feedback. I certainly will check each one and submit my work for each one. It was really good to hear that I did a good job; I was really worried I might have made some mistakes.

@Rawan0-0 Rawan0-0 added the 📅 Sprint 2 Assigned during Sprint 2 of this module label Sep 30, 2026
@github-actions

This comment has been minimized.

@Rawan0-0 Rawan0-0 added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 6, 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 Oct 6, 2026
@Rawan0-0 Rawan0-0 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 Oct 6, 2026
@github-actions

This comment has been minimized.

1 similar comment
@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 Oct 6, 2026
@Rawan0-0 Rawan0-0 added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 6, 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 Oct 6, 2026
@github-actions

This comment has been minimized.

@Rawan0-0 Rawan0-0 added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 6, 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 Oct 6, 2026
@Rawan0-0 Rawan0-0 changed the title London | 26-ITP-Sep | Rawan Almutairi | Sprint2 | JavaScript exercises London | 26-ITP-Sep | Rawan Almutairi | Sprint 2 | JavaScript exercises Oct 6, 2026
@Rawan0-0 Rawan0-0 added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 6, 2026

@abdishakoor-dev abdishakoor-dev left a comment

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.

Rawan, you've answered every question, and some of the hardest parts are right: dir and ext in 3-paths.js work for any file name, and your fixes in 1.js and 4.js run. I ran each file with node, and a few answers need another go before this can be marked Complete. I've left a step-by-step hint on each one.

How to run a file: in VS Code, right-click the folder (for example 2-mandatory-errors), choose Open in Integrated Terminal, then type node 3.js and press Enter. Run each file after you change it.

What to do:

  1. 3-to-pounds.js: delete the copied code on lines 48 to 53 so the file runs again, then add the value to each step (hints on lines 44 and 49).
  2. 2.js: change the order of the code so it prints I was born in Bolton (line 4).
  3. 3.js: fix line 2 and change ReferenceError to TypeError (line 10).
  4. 1.js, 2.js, 3.js, 4.js: copy the error message node prints into each file (line 6 of 1.js shows how).
  5. 4-random.js: fix "nearest" on line 22 and say what num is.
  6. 2-time-format.js: redo c), d) and f) (lines 22 and 26).
  7. 1-percentage-change.js e): say what Number(...) does (line 24).
  8. Delete lines that start with // and contain old code: 3-paths.js lines 12-15, 21-22, 35, 37, 39, plus your notes on lines 29 and 60; 2-initials.js line 8; 4.js lines 5-6 (after you've copied its error message).
  9. Format each file: right-click inside the file, choose Format Document, then save. Do this for all 12 files.

Once these are pushed, I expect to mark this Complete. Add the Needs Review label again when you have pushed.

//paddedPenceNumberString.substring value is found by starting from the first index WITH LENGTH 3 and ending with paddedPenceNumberString.length subtracted by the operator 2

// IN THIS LINE const pence = paddedPenceNumberString
const pence = paddedPenceNumberString

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.

Lines 49 to 53 are copies of the program's own code (lines 14 to 18), so const pence is now created twice. Node refuses to run the file: SyntaxError: Identifier 'pence' has already been declared.

Delete lines 48 to 53, then run node 3-to-pounds.js. You should see £3.99 printed once. Your explanation should only be // comments; the program itself stays exactly as it was given.

// 0,
//paddedPenceNumberString.length - 2
//);
// we assign the value to be starting with MINUMUM LENGTH IS 3 CHARACTERS than if not ADD THE VALUE 0 TO THE BEGINNING

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 steps say which method is used, but not what it gives. Write the value each line produces for "399p". Here is step 2 as an example:

// 2. penceString.length is 4, so penceString.length - 1 is 3.
//    substring(0, 3) keeps characters 0, 1 and 2, giving "399" (the p is removed).

Now do the same for the rest, filling in the ...:

// 3. padStart(3, "0") gives "..."
// 4. pounds is "..."
// 5. pence is "..."
// 6. the console.log prints ...

Then change line 1 to "9p", run it, and write down what it prints. What did padStart do to "9"? Change line 1 back to "399p" afterwards.

@@ -3,3 +3,5 @@

console.log(`I was born in ${cityOfBirth}`);

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 explanation on line 7 is right. JavaScript runs the file from top to bottom, and line 4 uses cityOfBirth before line 5 has created it.

So what order should these two lines be in? Change it, run node 2.js, and you should see I was born in Bolton.

// Then run the code and see what error it gives.
// Consider: Why does it give this error? Is this what I predicted? If not, what's different?
// Then try updating the expression last4Digits is assigned to, in order to get the correct value
// in this case its a reference error the program is trying to access a value that wasn't declared. In this case a variable. 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.

This one isn't a ReferenceError. Run the file and look at the last line of the error: node says TypeError: cardNumber.slice is not a function. cardNumber is there (line 1), but it holds a number, and .slice() only works on strings.

  1. In your thread reply you found toString(). Put it between cardNumber and .slice(-4) on line 2. Add console.log(last4Digits); underneath and run it: you should see 4213.
  2. Replace line 10 with three comments in your own words:
// Prediction: ...
// Error: TypeError: cardNumber.slice is not a function
// Why: ...

let age = 33;
age = age + 1;

//we change the variable declaration and reassign its value

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 fix is right. This section also wants the error message node gives for the original code. To see it:

  1. Change let back to const on line 3 and run node 1.js.
  2. Copy the line that starts with TypeError into a comment here.
  3. Change const back to let.

Do the same in 4.js (remove the // from line 5 for a moment), and in 2.js and 3.js before you fix them. Each file should end up with the error message and your explanation.

// * is a multiplication operator
// to understand what is going on we need to understand what the floor and random methods do
//Math.floor (rounds down to the nearest whole number) and than pass it to Math.floor
// we are asking the program to round whatever result we have to the nearest whole number 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.

Two things here.

  1. Math.floor always rounds down, as you said on line 21. Math.floor(4.9) is 4, not 5. Change "nearest" on line 22.
  2. The question asks what num represents. Add console.log(num); after line 4 and run the file ten times. Then finish with one line:
// So num is a random whole number from ... to ...

Your thread reply already explains why the + 1 is there, so you can copy that in too.

// "operator returns the remainder left over when one operand is divided by a second operand. It always takes the sign of the dividend."
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?

// it means the number of minutes in a film is calculated by calculating the number of seconds in the film

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.

c) and d) need the numbers from this program. Add these two lines after line 4 and run the file:

console.log(remainingSeconds);
console.log(totalMinutes);

Then fill in:

// c) movieLength % 60 is ..., which is the seconds left over after ...
// d) totalMinutes is ..., the number of whole minutes. Line 4 takes away remainingSeconds first so that ...

Delete the two console.log lines afterwards.


//the variable result represesnt the length of the film in hours,minutes,and seconds. A better name would be movie time.
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
// However, it doesn't work when the leading number of a decimal is zero like this 08784 because it interpreted as octal literal and 8 can't work in octal numeration

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.

const movieLength = 08784; actually runs and prints 2:26:24, because 8 isn't an octal digit, so JavaScript reads it as a normal number. So this answer needs changing.

Change line 1 to each of these, run the file, and write down what it prints: 59, 3605, -100, 90.5. Would you show 0:0:59 to someone as a time? What would you expect it to look like instead? Write one sentence for each value that doesn't look right. Put line 1 back to 8784 afterwards.


//four lines 1,2,7,8
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
//The replace.all method is used to include the car price and the price after one year of depreciation.

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.

You've explained replaceAll. Now Number(...). Add these two lines and run the file:

console.log(typeof carPrice); // put this before line 4
console.log(typeof carPrice); // put this after line 4

What changes? Write one sentence about what Number(...) did, and why line 7 needs it before subtracting. Then delete the two lines.

@abdishakoor-dev abdishakoor-dev 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 Oct 6, 2026
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. 📅 Sprint 2 Assigned during Sprint 2 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants