Conversation
✅ Deploy Preview for cyf-onboarding-module ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
abdishakoor-dev
left a comment
There was a problem hiding this comment.
Your answers in 1.js, 2.js and 4.js are clear. Each one has node's message, the reason, and a fix that runs. Prettier passes on every file, too.
Some answers need another look before I can mark this Complete:
1-key-exercises/3-paths.jsline 31: checkdiragainst the diagram.1-key-exercises/4-random.js: break the expression down, step by step.2-mandatory-errors/3.js: the fix changes the wrong line.3-mandatory-interpret/1-percentage-change.js: answers a), b) and d).3-mandatory-interpret/2-time-format.js: answers b), d), e) and f).3-mandatory-interpret/3-to-pounds.js: lines 29 to 35 say some values are numbers. There is also no step for line 18.- Delete the old code you commented out. Git keeps the old version for you. That is
3-paths.jslines 24 to 30,1.jslines 3 and 4,2.jslines 4 and 5,3.jsline 2 and4.jslines 1 and 2. Also delete the secondconsole.log(result);on line 29 of2-time-format.js.
See my comment on each line. Add the Needs Review label again once you have pushed.
| //const dir = filePath.slice(0 + lastSlashIndex); | ||
| //const dir = filePath.slice(0 + (lastSlashIndex - 1)); | ||
| //const dir = filePath.slice(0 + (lastSlashIndex - 44)); | ||
| const dir = filePath.slice(0, lastSlashIndex + 1); |
There was a problem hiding this comment.
Log dir and compare it with the diagram. Your dir ends with a /. Is that last / part of dir? Or is it the separator between dir and base?
There was a problem hiding this comment.
The last trailing slash is part of dir, because from what I've found, directory path variables should end with a trailing slash to clearly indicate that they represent directories. Edit. I see, for Unix it's different. Will fix it.
| // Try logging the value of num and running the program several times to build an idea of what the program is doing | ||
|
|
||
| console.log(num); | ||
| // This expression uses a function that returns a random number between (min)1 and (max)100. |
There was a problem hiding this comment.
The range is right. The exercise also asks you to break the expression down. What does Math.random() give? What does Math.floor do to it? Which part makes the smallest value 1?
There was a problem hiding this comment.
Math.random() gives a decimal between 0 < 1. I multiply it by 100 to stretch it out, then Math.floor() chops off the decimals to make it a whole number. That gives me 0 to 99. The minimum at the end just adds 1 to the whole thing, so now it goes from 1 to 100 instead of 0 to 99
| // The actual error indicates that on the 3rd line there is a typeError: "cardNumber.slice is not a function" | ||
| // Checked the error reference and decided to look more closely. Noticed that the card number is used as a number, | ||
| // so it answers why the function couldn't be called - because they can be only called on Arrays and Strings. | ||
| // Therefore, I'll add parentheses to turn the card number into a string (so that the function could be called) |
There was a problem hiding this comment.
Your explanation of the error is good. But look at line 1. You changed cardNumber itself into a string. The exercise asks you to change the expression on line 3 instead. How can line 3 turn the number into a string?
|
|
||
| // a) How many function calls are there in this file? Write down all the lines where a function call is made | ||
|
|
||
| // 4, 5, 8 |
There was a problem hiding this comment.
Look at line 8 again. Is anything called there? And look at line 10. What is console.log(...)? Also, how many calls are there in total? Line 4 has two.
| // 4, 5, 8 | ||
| // 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? | ||
|
|
||
| // It was a syntax error, it can be fixed by adding the missing part (1 of 2 parentheses) |
There was a problem hiding this comment.
Node says "missing ) after argument list", but a bracket was not the problem. Compare line 5 with line 4 in the original. What was missing between the two arguments? And which line was it?
| // 6 | ||
| // b) How many function calls are there? | ||
|
|
||
| // 5 |
There was a problem hiding this comment.
Which five? % and / are operators, not function calls. Look for a name followed by (...).
|
|
||
| // d) Interpret line 4, what does the expression assigned to totalMinutes mean? | ||
|
|
||
| // total minutes (in seconds) - remaining seconds = remaining seconds. Then converts the seconds into minutes |
There was a problem hiding this comment.
Line 4 starts with movieLength, not total minutes. What is 8784 - 24? Why does the program take the 24 seconds away before it divides by 60?
| // total minutes (in seconds) - remaining seconds = remaining seconds. Then converts the seconds into minutes | ||
| // e) What do you think the variable result represents? Can you think of a better name for this variable? | ||
|
|
||
| // It represents how much of the movie is left to watch. Maybe something like remainderOfTheMovie |
There was a problem hiding this comment.
Run the file. It prints 2:26:24. movieLength is the length of the whole movie. So is result the time left to watch?
|
|
||
| // It represents how much of the movie is left to watch. Maybe something like remainderOfTheMovie | ||
| // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer | ||
| // It won't work with all values. Most importantly, the value must be strictly numeric and positive |
There was a problem hiding this comment.
Try some values and write down what each one prints. Try 59, -90 and 90.5. Would you show a time that way?
| // 3-6. const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1); | ||
| // : initializes a variable, the value of which is turned to numerical by removing the letter "p". | ||
| // 8. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); | ||
| // Here the padstart function turns "399" string into 399 number (it could add some zeroes in front, but here it serves as a converter) |
There was a problem hiding this comment.
Does padStart turn "399" into a number? Change line 1 to "5p" and run it. What does each line give now? That shows what padStart and padEnd are for.

Learners, PR Template
Self checklist
Task code
CYF-1039
Changelist
This branch was recreated from main so that it contains only Sprint-2 coursework.