Skip to content

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

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

zakiaao-tech wants to merge 17 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 f738b2f
🔍 Latest deploy log https://app.netlify.com/projects/cyf-onboarding-module/deploys/6ab2f3926af6b70008c9c754
😎 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.

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?

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?

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?

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?

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?

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?

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.

// 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.

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?

@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants