Skip to content

London | 26-ITP-Sep | Sakiya Mayow | Sprint 2 | JavaScript-Fundamentals - #1573

Open
zakiaao-tech wants to merge 19 commits into
CodeYourFuture:mainfrom
zakiaao-tech:sprint-2
Open

zakiaao-tech wants to merge 19 commits into
CodeYourFuture:mainfrom
zakiaao-tech:sprint-2

Conversation

@zakiaao-tech

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 the 4 exercises for my coursework, and provided answers where needed. These exercises included slice() methods, functions, index, number, variables, mathematical calculations, correcting errors, dividing, and objects.

@netlify

netlify Bot commented Sep 22, 2026

Copy link
Copy Markdown

Deploy Preview for cyf-onboarding-module ready!

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

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

Thanks for rebuilding the branch. It is clean now, with only your 14 Sprint 2 commits.

Your explanations are detailed. In 4-random.js you work through the expression in the right order.

There is one big problem first. Most of your answers are written as plain text in the .js files. Node reads every line of a .js file as code. Your answers are sentences, not code. So 10 of your 12 files stop with a SyntaxError. Only 2-initials.js and 3-paths.js run.

You already wrote the fix in your answer in 0.js. Two slashes // turn a line into a comment. Node ignores comments, so it does not try to run them.

The rule: in a .js file, every line of an answer must start with //.

After that, run each file with node to check it works.

Things to fix before I can mark this Complete:

  1. Put // at the start of every answer line, in every .js file. See my comment on 1-count.js.

  2. 2-mandatory-errors/0.js: lines 1 and 2 still run. See my comment.

  3. 2-mandatory-errors/2.js: lines 6 and 7 still run. See my comment.

  4. 3-mandatory-interpret/1-percentage-change.js line 5: the comma is still missing, so the file cannot run.

  5. 1-key-exercises/3-paths.js: dir and ext are not right yet. See my comments.

  6. 1-key-exercises/4-random.js line 26. See my comment.

  7. 2-mandatory-errors/1.js, 2.js and 4.js: add the name of the error. The prep shows three error names: SyntaxError, TypeError and ReferenceError. Which one was each?

  8. 2-mandatory-errors/3.js: the fix changes the wrong line. See my comment.

  9. 3-mandatory-interpret/2-time-format.js: answers c) and f), and e) still needs a better name for result.

  10. 2-initials.js line 8: delete the old starter line. Git keeps it for you.

  11. Formatting. "My changes follow the style guide" is on your checklist, and consistent formatting is part of it. The tool that does it is called Prettier. It cannot format a file with a SyntaxError, so do this after step 1.

    Prettier comes with the CYF extension pack from onboarding. If you are not sure you have it, open VS Code, go to Extensions, and search for CodeYourFuture Extension Pack: https://marketplace.visualstudio.com/items?itemName=CodeYourFuture.cyf-extension-pack

    Then open each file you changed, right click in the editor, and choose Format Document. Pick Prettier if VS Code asks. Save, commit and push. To format every time you save, follow the format on save steps here: https://github.com/CodeYourFuture/Module-JavaScript-Fundamentals/blob/main/practical_guide.md

Add the Needs Review label again once you have pushed.

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



Line 1 is a declaration and Line 3 is a statement that changes the value of the variable 'count' by adding 1 to its current 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 answer is right. But run node 1-count.js. Node stops here with a SyntaxError. It tries to read your sentence as code.

Start each answer line with //. Then the line is a comment, and node skips it. Do this in every .js 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.

All your answers are comments now, and every file runs. Good.

Comment thread Sprint-2/2-mandatory-errors/0.js Outdated
@@ -1,2 +1,6 @@
This is just an instruction for the first activity - but it is just for human consumption
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

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.

Run node 0.js. Line 1 has no //, so node still reads it. Also, the original line 2 is now split over lines 2 and 3. Where does each // need to go?

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.

Both lines are comments now, and the file runs.

Comment thread Sprint-2/2-mandatory-errors/2.js Outdated

error

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.

Lines 6 and 7 are the original code, and they still run. So the file still stops with the same error. Your fixed version on lines 16 and 17 is right. What should happen to lines 6 and 7?

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 file runs now, and your error / right way layout is clear. Good.

Comment thread Sprint-2/1-key-exercises/3-paths.js Outdated

const dir = ;
const ext = ;
const dir = filePath.slice(1, lastSlashIndex);

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.

Log dir. It prints Users/mitch/.... The path starts with a /. In the diagram, the root / is part of dir. Which index does your slice start at?

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.

dir is right now.

Comment thread Sprint-2/1-key-exercises/3-paths.js Outdated
const ext = ;
const dir = filePath.slice(1, lastSlashIndex);

const ext = base.slice(45);

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.

Log ext. What does it print? base is "file.txt", only 8 characters. What is at index 45? Line 13 finds the last /. Could you find the . the same 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.

ext prints .txt now, and it works for any file name. Good.

Comment thread Sprint-2/1-key-exercises/4-random.js Outdated
Next, we need to multiply the result from Math.random() by 100. This may give us the result of a decimal between 0 and 100.
Next step is to use Math.floor() wich then rounds down the decimal number to the nearest whole integer. This then means that the result will be a whole number between 0 and 99.
But we want 1-100, so we add 1 to the result of Math.floor() this then changes the range to be inclusive of 1 and 100.
After adding 1, we need to round down the number to the nearest interger, this is done by using Math.floor(). After this we will have a whole number between maximum and minimum.

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.

Look at line 4 again. How many times is Math.floor used? Does it happen before or after + minimum?

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.

Line 21 is right. But line 29 still says you round down after adding 1. That is the opposite order. Delete line 29.

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.

Line 29 is gone, and the order is right now.

Comment thread Sprint-2/2-mandatory-errors/3.js Outdated

When run with console.log(last4Digits); we get --> TypeError : cardNumber.slice is not a function

.slice is a method used with strings and we need to make cardNumber into a string by adding quotation marks.I

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 and the error message are good. But you changed cardNumber on line 1 into a string. The exercise asks you to change the expression on line 2 instead. How can line 2 turn the number into a 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.

Line 21 is exactly right. Just check it says cardNumber, with a capital N.

You pass cardNumber to the function String. It converts the number into a string. You explained this in your comment. But in your code, you made it a string by hand. You put quotes around the number on line 1.

Please update your code to use String. That is what it is designed to do. Put line 1 back to the number, then change line 2.

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.

Line 2 uses String now, and line 1 is a number again. Your code is right, and line 21 explains it well.

Some old notes still describe your first fix. Line 19 ends with "by adding quotation marks". Lines 23 and 24 say you put quotes around the number on line 1. You don't do that any more. Please change the end of line 19 to match your new fix, and delete lines 23 and 24.

There are 5 function calls, two function calls on line 4 = Number(...) and replaceAll(...) two more on line 5 = Number(...) and replaceAll(...) and finally on line 10 = console.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?

SyntaxError: missing a comma to separate the arguments

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.

Right reason. Which line is the error on? The comma is still missing on line 5, 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.

The comma is fixed and the file runs. The question also asks which line the error was on. Add the line number.

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.

Line 5 is right. Done.

// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators

// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
movieLength % 60 means finding the remainder after dividing movieLength by 60. movieLength = 8784 so we need to do: 8784 % 60 = 146.4 and the nearest whole integer is 146.

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.

Is 146.4 what 8784 % 60 gives? Or is that 8784 / 60? Try both in node and compare.

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.

Line 25 is right: 8784 % 60 is 24. But line 23 says 8784 % 60 = 146.4. Did you mean / instead of % on line 23?

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, thanks.

The result variable will show us he complete results from our calculations of = totalHours:remainingMinutes:remainingSeconds.
result = 2:26:24
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
I tested differnet codes: 7965 and I got the result 2:12:45 and i also tried : 2654 and got 0:44:14. 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.

Both of those work. Now try 59, -90 and 90.5. What does each one print? Does the code work for all values?

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. 59, -90 and 90.5 all answered.

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

That is most of the list done, thanks. Every file runs now, and 3-paths.js gives the right dir and ext.

Still to do before I can mark this Complete:

  1. 2-mandatory-errors/1.js, 2.js and 4.js: the error type is still missing. See my comment on each file.
  2. 2-mandatory-errors/3.js: the fix is still on line 1. Your line 21 says the right thing. See my comment.
  3. 4-random.js line 29 and 2-time-format.js line 23. See my comments.
  4. 2-time-format.js answer e): a better name for the variable result is still missing.
  5. 1-percentage-change.js answer b): which line was the error on?
  6. Prettier again. All 14 files still fail. Format each file you changed, then push. Format on save does it for you every time: https://github.com/CodeYourFuture/Module-JavaScript-Fundamentals/blob/main/practical_guide.md

Add the Needs Review label again once you have pushed.

Comment thread Sprint-2/2-mandatory-errors/1.js Outdated



//const means that the variable age is a constant and cannot be reassigned. When we try to reassign the value of age by adding 1 to it, we get an error.

@abdishakoor-dev abdishakoor-dev Sep 23, 2026

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 reasoning. You explain why const cannot be reassigned, and why let fixes it.

You also need to name the error type. JavaScript has different error types. The prep covered three: TypeError, ReferenceError and SyntaxError. The error type will be obvious from the error itself. Which one is this? Please add it to your explanation of the error.

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 error type is TypeError. It is the first word of the error message node showed when you ran the original file.

Please add this line above your explanation on line 9:

// The error is a TypeError: Assignment to constant variable.

//console.log(`I was born in ${cityOfBirth}`);
//const cityOfBirth = "Bolton";

//The reason there is an error is because we are using the wrong order, we are telling Javascript to print the value of cityOfBirth before creating a variable.

@abdishakoor-dev abdishakoor-dev Sep 23, 2026

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 reasoning. You explain that JavaScript runs from top to bottom, so the variable must be declared first.

You also need to name the error type. JavaScript has different error types. The prep covered three: TypeError, ReferenceError and SyntaxError. The error type will be obvious from the error itself. Which one is this? Please add it to your explanation of the error.

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 error type is ReferenceError. It is the first word of the error message node showed when you ran the original file.

Please add this line above your explanation on line 9:

// The error is a ReferenceError: Cannot access 'cityOfBirth' before initialization




//Variable names cannot start with a number as Javascript doesn't allow it, it can contain a number inside the variable but not at the beginning.

@abdishakoor-dev abdishakoor-dev Sep 23, 2026

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 reasoning. A variable name cannot start with a number.

You also need to name the error type. JavaScript has different error types. The prep covered three: TypeError, ReferenceError and SyntaxError. The error type will be obvious from the error itself. Which one is this? Please add it to your explanation of the error.

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 error type is SyntaxError. It is the first word of the error message node showed when you ran the original file.

Please add this line above your explanation on line 12:

// The error is a SyntaxError: Invalid or unexpected token

//we then subtract remainingSeconds from movieLength= 8784 -24 = 8670. we then have to divide it by 60 which gives us 8760 / 60 = 146. we divide because there is 60 seconds in one minute, and right now we are converting seconds into minutes.

// e) What do you think the variable result represents? Can you think of a better name for this variable?
//>The result variable will show us he complete results from our calculations of = totalHours:remainingMinutes:remainingSeconds.

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 to the first part of e) is right. The question also asks for a better name for the variable result.

The name result is vague. Any calculation has a result. So the name does not tell us what this value is.

Can you suggest a better name? Pick one that explains what this value is.

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.

A good name says what the value is. result holds the movie length, written as hours:minutes:seconds. So a name like movieDuration or formattedTime works. Pick one of these, or your own, and add it to e).

@abdishakoor-dev abdishakoor-dev removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Sep 23, 2026
@zakiaao-tech zakiaao-tech added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Sep 23, 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 done. 3.js now uses String on line 2, and your answer to b) names line 5.

Still to do before I can mark this Complete:

  1. 1.js, 2.js and 4.js: the error type is still missing. My reply on each file has the line to add.
  2. 2-time-format.js e): a better name for result. See my reply.
  3. 3.js: your code is right. But some old notes describe your first fix. Please update the end of line 19, and delete lines 23 and 24.
  4. Prettier: all 14 files still fail. Open each file you changed, right click, and choose Format Document. If Prettier is not in the list, install the CYF extension pack first: https://marketplace.visualstudio.com/items?itemName=CodeYourFuture.cyf-extension-pack
    To format every time you save, follow these steps: https://github.com/CodeYourFuture/Module-JavaScript-Fundamentals/blob/main/practical_guide.md

Add the Needs Review label again once you have pushed.

@abdishakoor-dev abdishakoor-dev removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Sep 23, 2026
@zakiaao-tech zakiaao-tech added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Sep 23, 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. Every file runs, the error types are in, and Prettier passes on all your files now. Marking this Complete. Well done.

A few small things for your next PRs. You don't need to change them here:

  1. Variable names in JavaScript use camelCase. Each new word starts with a capital letter, so movieTime, not movietime (2-time-format.js line 34).
  2. Delete old code instead of leaving it commented out, like //console.log(result); on line 35 of 2-time-format.js. Git keeps the old version for you.
  3. Check that the explanations in your comments match your code. 3.js lines 23 and 24 say cardNumber becomes a string. But cardNumber is still a number. String(cardNumber) makes a new string from it, and .slice uses that.

@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. Reviewed Volunteer to add when completing a review with trainee action still to take. labels Sep 23, 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