Skip to content

London | 26-ITP-Sept | Fung Nin Lee | Sprint 2 | JavaScript Fundamentals - #1555

Open
leerogerfn wants to merge 34 commits into
CodeYourFuture:mainfrom
leerogerfn:coursework/sprint-2
Open

leerogerfn wants to merge 34 commits into
CodeYourFuture:mainfrom
leerogerfn:coursework/sprint-2

Conversation

@leerogerfn

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

Task code

CYF-1039

Changelist

I completed all 4 sections of sprint 2 coursework.

@netlify

netlify Bot commented Sep 20, 2026

Copy link
Copy Markdown

Deploy Preview for cyf-onboarding-module ready!

Name Link
🔨 Latest commit 304a0b2
🔍 Latest deploy log https://app.netlify.com/projects/cyf-onboarding-module/deploys/6ab13558c9c65f00080f1742
😎 Deploy Preview https://deploy-preview-1555--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.

@leerogerfn leerogerfn added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Sep 20, 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.

You answered every question, and your commits are small and clear. Good work.

Before I can mark this Complete:

  1. Six files stop with an error when you run them. The cause is the same in all six. Your answers are plain text, with no // in front. So node tries to run your answers as code. The files are 1-count.js, 4-random.js, and 0.js, 1.js, 2.js, 3.js in 2-mandatory-errors.
    The rule: every line that is not code needs // in front.
    After you fix it, run each file with node. There should be no SyntaxError.

  2. In 2-mandatory-errors, the code needs fixing, not only explaining. 1.js, 2.js and 3.js still have the original bug. See my comments.

  3. Some answers in 3-mandatory-interpret need another look: 1-percentage-change.js a), d) and e), and 2-time-format.js f). See my comments.

  4. Please delete the Sprint-2/prep folder. It has your practice files from the prep. They are not part of this task. If you want to keep them, copy them to a folder outside the repo first. Then, in VS Code, right-click the prep folder and choose Delete. Commit and push.
    Next time, do not stage practice files. Only commit the files the task asks for.

  5. Most files fail the formatting check. The tool that formats code is called Prettier. It comes with the CYF extension pack from onboarding. If you are not sure you have it, search Extensions in VS Code for CodeYourFuture Extension Pack: https://marketplace.visualstudio.com/items?itemName=CodeYourFuture.cyf-extension-pack
    Open each file you changed. Right-click in the editor and choose Format Document. If VS Code asks, pick Prettier. Save, commit and push. To format on every save, follow these steps: https://github.com/CodeYourFuture/Module-JavaScript-Fundamentals/blob/main/practical_guide.md
    Do this after step 1. Prettier cannot format a file that has an error.

Add the Needs Review label again when you have pushed.

Comment thread Sprint-2/2-mandatory-errors/0.js Outdated
We don't want the computer to run these 2 lines - how can we solve this problem? No newline at end of file
We don't want the computer to run these 2 lines - how can we solve this problem?

adding // before the lines. 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.

Your answer is right. Now do it in the file. Put // before lines 1 and 2, and before your answer on line 4. Then node 0.js should print nothing.

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.

That's it. The file runs with no output now.

Comment thread Sprint-2/1-key-exercises/4-random.js Outdated

math.floor is round down the number returns to largest integer less than or equal to a given number.
math.random() could generate the number from 0 to <1 b random.
maximum refer to 100 and minimum refer to 0.

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 of Math.floor and Math.random() is right. This line says minimum is 0. Check line 1 again.

The question asks what num is. What is the smallest value num can be? And the largest? Run the file several times to check.

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.

Fixed now. Good.

Comment thread Sprint-2/2-mandatory-errors/1.js Outdated
console.log(age)

The error is "Assignment to constant variable." Constant value could not be alternated.
if line 3 const changed to let the code could be executed. 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.

Your error message and your reason are right. But line 3 is still const. So the error is still there. Please make the change in the code too.

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.

Fixed. Good.

Comment thread Sprint-2/2-mandatory-errors/2.js Outdated
console.log(`I was born in ${cityOfBirth}`);
const cityOfBirth = "Bolton";

Initialization should access before the declaration. 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 message does node print for this file? Please write it here.

Then look at the order. Which line runs first, 4 or 5? Fix the code so it prints "I was born in Bolton".

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 code works now, good. The error message is still missing. Swap lines 4 and 5 back for a moment. Run the file and copy what node prints to line 7. Then swap them again.

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.

Thanks for adding a message. But it is not from this code. "Cannot find module" means node could not find the file. Look at the path in the message: Sprint-2/2.js.

Please do these steps:

  1. Line 19 is a } with no //. Delete it.
  2. In VS Code, right-click the 2-mandatory-errors folder and choose Open in Integrated Terminal. Run node 2.js.
  3. Copy only the first line of the error to line 8, with // in front. Delete the other error lines.
  4. Put lines 4 and 5 back in the working order. Run the file again. It should print "I was born in Bolton".

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.

That's the right message now, and the file works. Good.

Comment thread Sprint-2/2-mandatory-errors/3.js Outdated
// 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

slice is for text or array only. Need to change card number from number to text. Add ''for 4533787178994213. 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.

Your prediction is right. slice does not work on a number.

Two more steps. Run the file and write down the error node prints. Then fix line 2 so last4Digits gets "4213". The task asks you to change line 2, not the number on line 1.

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 fix works, good. The error message is still missing. Remove .toString() for a moment and run the file. Write down the error node prints. Then put .toString() back.

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.

That's the right message. You only need the first line. You can delete the lines below it.

Now add .toString() back on line 2, so the file prints 4213 again.

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.

Fixed. Good.

Comment thread Sprint-2/2-mandatory-errors/4.js Outdated
const twelveHourClockTime = "8:53pm";
const twentyFourHourClockTime = "20:53";

//integer/number could not start for the initiation. 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.

Your new names work, and the file runs now. Your reason is right too. A name cannot start with a number.

What did node print for the original names? Please add that message here.

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.

Message added. Good.

// Read the code and then answer the questions below

// a) How many function calls are there in this file? Write down all the lines where a function call is made
//A: 3

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.

There are more than 3 calls. Number(...) is a call. replaceAll(...) is a call too. How many calls are on line 4? And on line 5?

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.

Closer, but 6 is not right. Write the name of each call, one per line. How many names do you get?

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.

That's right now. Good.

//priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));

// d) Identify all the lines that are variable declarations
//const priceDifference = carPrice - priceAfterOneYear;

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 7 and 8 are right. A declaration is any line that creates a variable. let creates a variable too. What do lines 1 and 2 do?

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.

All four now. Good.

//const percentageChange = (priceDifference / carPrice) * 100;

// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
//A: replacing , with empty string.

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.

That is what replaceAll does. What does Number(...) then do to the result? Why does line 7 need it?

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.

Yes, that is the purpose.

//A: Duration

// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
// Yes. Because the variables declaration stated clearly.

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.

Try movieLength as 59, then -60, then 90.5. What does each one print? Would you show a time that way?

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.

Good answer.

@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 Sep 21, 2026
@leerogerfn leerogerfn 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 Sep 21, 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.

Nearly all done, and every file now runs without an error. Three small things left:

  1. 2-mandatory-errors/2.js line 7: write down the error message node prints.
  2. 2-mandatory-errors/3.js line 13: the same. The error message is still missing.
  3. 3-mandatory-interpret/1-percentage-change.js line 15: count the calls again.

Add the Needs Review label again when you have pushed.

@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 Sep 21, 2026
@leerogerfn leerogerfn 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 Sep 21, 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.

Question a) is right now. Two files do not run at the moment:

  1. 2-mandatory-errors/2.js: see my comment for the steps.
  2. 2-mandatory-errors/3.js line 2: add .toString() back.

Run both files with node before you push. Each should print the right result. Then format both files with Prettier.

Add the Needs Review label again when you have pushed.

@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 Sep 21, 2026
@leerogerfn leerogerfn 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 Sep 21, 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.

All fixed, and every file runs. Marking this as Complete. Well done.

@abdishakoor-dev abdishakoor-dev 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 Sep 21, 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants