Conversation
✅ Deploy Preview for cyf-onboarding-module ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
|
||
| // Answers | ||
|
|
||
| // a) There are no function or function calls in this code. |
There was a problem hiding this comment.
How are functions usually invoked in JS?
There was a problem hiding this comment.
In JS functions are invoked when the function's name is written followed by parentheses.
There was a problem hiding this comment.
You answered this well in the thread: a function is called with its name and parentheses. Now use that on the file. Number(...) is a function call. What else on lines 4, 5 and 10 has a name followed by (...)? Please update answer a) on line 26.
|
|
||
| // a) There are 6 variable declarations. | ||
|
|
||
| // b) There are no function calls. |
There was a problem hiding this comment.
Similar question to the one I left in previous file
There was a problem hiding this comment.
Is this question about variables or functions?
There was a problem hiding this comment.
It is about functions. A function call is a name followed by (...). % and / are operators, not function calls. Is there any name followed by (...) in lines 1 to 10? Please update b) on line 31.
| // Try logging the value of num and running the program several times to build an idea of what the program is doing | ||
|
|
||
| // 1. num is a variable that stores the final result of the expression assigned to it. | ||
| // 2. The Math.random() method generates a random decimal number from 0 up but not excluding 1. |
There was a problem hiding this comment.
Could be worth having another look at Math.random docs here.
There was a problem hiding this comment.
The Math.random() method returns a pseudo-random floating number between 0(inclusive) and 1(exclusive).
There was a problem hiding this comment.
Line 12 is right now. One thing is still missing. Your steps say how num is made, but not what it is. What is the smallest value num can be? And the largest? Add one line at the end that says what num is.
| const dir = ; | ||
| const ext = ; | ||
| const dir = filePath.slice(0, lastSlashIndex); | ||
| const ext = filePath.slice(-3); |
There was a problem hiding this comment.
Can you think of a more robust way to find extention?
There was a problem hiding this comment.
It'a changed to const ext = filePath.slice(filePath.length -3)
There was a problem hiding this comment.
filePath.slice(filePath.length - 3) gives the same result as slice(-3). It always takes the last 3 characters. Try it with photo.jpeg. You get peg, not jpeg.
The code on lines 13 and 14 already solves the same kind of problem for base:
- Line 13 finds the position of the last
/withlastIndexOf("/"). - Line 14 slices from that position to the end.
The extension starts at the last . in the path. Can you do the same two steps, but with "." instead of "/"?
| @@ -1,9 +1,16 @@ | |||
| const cardNumber = 4533787178994213; | |||
| const last4Digits = cardNumber.slice(-4); | |||
| const last4Digits = Number(String(cardNumber).slice(-4)); | |||
There was a problem hiding this comment.
Can you think of any edge cases that could surface here?
There was a problem hiding this comment.
An cardNumber = "" can return empty string. cardNumber = 123 can return 123.
There was a problem hiding this comment.
Your first version was very good: Number(String(cardNumber).slice(-4)). Now you changed line 1 into a string instead. But the exercise asks you to update the expression on line 2, and line 16 still talks about Number(). Please go back to your first version.
|
|
||
| // c) The reminder (%) operator returns the reminder left over when one operand is divided by a second operand. | ||
|
|
||
| // d) movieLength(8784) - remainingSeconds(24) = 8760(seconds). 8760 / 60 gives us 146 minutes. totalMInutes = 146 |
There was a problem hiding this comment.
Nice! Great example of using real numbers to make explanation super clear.
There was a problem hiding this comment.
Thanks for taking the time to review my code and give feedback.
|
Good job! Very clear explanations/answers to most questions. Only few small bits to revisit here. |
abdishakoor-dev
left a comment
There was a problem hiding this comment.
Your answers are clear and well explained. Your breakdown of line 4 in 2-time-format.js is very good, with real numbers at each step. 3-to-pounds.js step 3 also has good examples, with 11 and 1.
I have left a hint on each line. Please fix these things before I can mark this Complete:
-
1-percentage-change.jsa) and2-time-format.jsb): both say there are no function calls. But both files have some. A function call is a function name followed by brackets, likename(...). For example,console.log(...)andNumber(...)are function calls. Look for this pattern in each file, and count them again. -
3-paths.jsline 21:extonly works when the extension has 3 letters. The code on lines 13 and 14 shows you a better way. See my reply on line 21. -
4-random.js: say whatnumis at the end. -
2-mandatory-errors:1.jshas no explanation.2.jsand4.jsneed the error type (SyntaxError, TypeError or ReferenceError). In3.js, change line 2, not line 1. -
2-time-format.js: answers c) and f). -
"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 sets spacing and indentation to one agreed style. Then a reviewer only sees the changes you meant to make. Right now all the files you changed fail that check.
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.
|
|
||
| const age = 33; | ||
| let age = 33; | ||
| age = age + 1; |
There was a problem hiding this comment.
The fix works. But the exercise also asks you to explain the error. Please add a comment with the error type and the reason.
The prep shows three error types:
- SyntaxError: the code breaks a rule of JavaScript, so no line runs.
- TypeError: the code tries to do something that value cannot do.
- ReferenceError: the code uses a variable it cannot reach.
When you ran the original file, node's error message started with one of these. Which one was it? And why does let fix it?
| const cityOfBirth = "Bolton"; | ||
| console.log(`I was born in ${cityOfBirth}`); | ||
|
|
||
| // Java script cannot access the variable cityOfBirth before initialization. No newline at end of file |
There was a problem hiding this comment.
Your reason is right, and the fix works. Please also write the error type.
The prep shows three error types:
- SyntaxError: the code breaks a rule of JavaScript, so no line runs.
- TypeError: the code tries to do something that value cannot do.
- ReferenceError: the code uses a variable it cannot reach.
When you ran the original file, node's error message started with one of these. Which one was it?
| const twelveHourClockTime = "8:53pm"; | ||
| const twentyFourHourClockTime = "20:53"; | ||
|
|
||
| // Variable names cannot start with a number in Java Script. No newline at end of file |
There was a problem hiding this comment.
Your reason is right, and the new names work. Please also write the error type.
The prep shows three error types:
- SyntaxError: the code breaks a rule of JavaScript, so no line runs.
- TypeError: the code tries to do something that value cannot do.
- ReferenceError: the code uses a variable it cannot reach.
When you ran the original file, node's error message started with one of these. Which one was it?
|
|
||
| // b) There are no function calls. | ||
|
|
||
| // c) The reminder (%) operator returns the reminder left over when one operand is divided by a second operand. |
There was a problem hiding this comment.
This is what % does in general. In this program, movieLength % 60 gives 24. Are those 24 seconds, minutes or hours? Write what the 24 means here.
|
|
||
| // e) result represents the length of the movie in hours, minutes, and seconds format. It can be renamed movieDuration. | ||
|
|
||
| // f) When displaying single digit hour, minute, or seconds it doesn't include 0 in front of the digit. No newline at end of file |
There was a problem hiding this comment.
Good, that is one problem. Now try -90 and 90.5 as movieLength. What does the program print each time? Add what you see to f).

Learners, PR Template
Self checklist
Task code
CYF-1039
Changelist
Using documentations errors explained fixed. Program explained step by step.