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 2-mandatory-errors answers are clear: each one has node's error message and a reason. 2.js and 4.js also run now. 3-paths.js works for any file name too, because you used lastIndexOf.
I have left a hint on each line. Before I can mark this Complete:
1.jsand3.jsstill stop with an error. Your notes say you fixed them, but the code has not changed.4-random.js: say whatnumis, and explain each part of line 4.1-percentage-change.js: answer a), and the line number in b).2-time-format.js: answers b), c) and d), and a better name in e).3-to-pounds.js: steps 2 and 5.2-initials.jslines 4 to 7: delete the old code you commented out. Git keeps the old version for you.- Prettier again: most of your files fail. Open each file you changed, right click, and choose Format Document. To make this happen 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.
| console.log(age) | ||
|
|
||
| // The TypeError: Assignment to constant variable implies we are trying to reassign the variable twice. | ||
| // This case, I have used let instead in order to allow the variable to be reused. No newline at end of file |
There was a problem hiding this comment.
Your explanation is right. But line 3 still says const, so the file still stops with the same TypeError. Did you forget to save or commit the change? Run node 1.js to check.
There was a problem hiding this comment.
Fixed. The file runs now.
| //Prediction was the code would run successfully without error although with the wrong results due to absence of syntax errors in the file | ||
| // Error returned: TypeError: cardNumber.slice is not a function | ||
| // Lesson learnt here; slice method is only available for strings or arrays not numbers | ||
| // So converted the cardNumber into a string first No newline at end of file |
There was a problem hiding this comment.
Your notes are right, and it is good that you wrote down your prediction. But line 2 has not changed. So the file still gives TypeError: cardNumber.slice is not a function.
How can line 2 turn cardNumber into a string before .slice? String(...) turns a value into a string.
There was a problem hiding this comment.
You changed line 1 into a string. But the exercise asks you to change line 2, the expression last4Digits is assigned to. The number on line 1 stays a number, and line 2 turns it into a string.
Please change lines 1 and 2 to this:
const cardNumber = 4533787178994213;
const last4Digits = String(cardNumber).slice(-4);Then update your note on line 15. Say that you used String() on line 2 to turn the number into a string.
There was a problem hiding this comment.
Fixed. The file prints 4213 now.
|
|
||
| // Answer: For calculations i utilised BODMAS formula solving numbers in brackets first, multiplication, subtraction and addition | ||
| // I used 0.68 for math.floor(random number) + 1 | ||
| // Sum = 69 No newline at end of file |
There was a problem hiding this comment.
Your example is a good start: 0.68 gives 69. Now say what num is in general. Log num and run the file a few times. What is the smallest value it can be? And the largest?
Also explain each part of line 4. Math.random() gives a decimal from 0 up to 1, but never 1. What does * 100 do to it? Then what does Math.floor do? And + minimum?
There was a problem hiding this comment.
Steps 2 to 4 are right. Two small things are missing: the largest value of num, and what + minimum does.
Please change step 1, and add a step 5, like this:
// 1. num is a random whole number from 1 to 100.
// 5. + minimum adds 1. So the range 0 to 99 becomes 1 to 100.|
|
||
| // a) How many function calls are there in this file? Write down all the lines where a function call is made | ||
|
|
||
| // 2 |
There was a problem hiding this comment.
Count again. A function call is a name followed by (...). Line 4 has two: Number(...) and .replaceAll(...). Line 5 has two as well. And what is console.log(...) on line 10?
There was a problem hiding this comment.
5 is right, and you are very close. Just fix two line numbers:
- Line 17: the second
Number()and.replaceAll()are on line 5, not line 4. - Line 18:
console.log()is on line 10. Please add "in line 10".
There was a problem hiding this comment.
Fixed. Both line numbers are right now.
| //priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ",")); | ||
| // 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? | ||
|
|
||
| //b) error = SyntaxError: missing ) after argument list |
There was a problem hiding this comment.
The error message is right, and your fix works. Which line was the error on? Write the line number too.
There was a problem hiding this comment.
Done. Line 5 is right.
| // 2 | ||
| // c) Using documentation, explain what the expression movieLength % 60 represents | ||
| // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators | ||
| // It means 60 % remainder of Movie length |
There was a problem hiding this comment.
% gives the remainder after a division. So movieLength % 60 is what is left after taking out the whole minutes. It gives 24. Are those 24 seconds, minutes or hours?
There was a problem hiding this comment.
24 seconds is right. Please delete the old answer above it: // It means 60 % remainder of Movie length.
| // It means 60 % remainder of Movie length | ||
|
|
||
| // d) Interpret line 4, what does the expression assigned to totalMinutes mean? | ||
| // totalMinutes is assigned a value of the result from (movieLength - remainingSeconds) / 60; |
There was a problem hiding this comment.
This repeats the code. What does it mean? First, movieLength - remainingSeconds takes away the 24 leftover seconds. Then it divides by 60. What does the result count?
There was a problem hiding this comment.
Good. Taking away the 24 seconds first means the division by 60 gives a whole number.
| // totalMinutes is assigned a value of the result from (movieLength - remainingSeconds) / 60; | ||
|
|
||
| // e) What do you think the variable result represents? Can you think of a better name for this variable? | ||
| // I think its the total movie length with a timer. Based on research it appears to be template literal variable as it mixes static text with dynamic data. Sorry I don't fully understand this bit yet |
There was a problem hiding this comment.
You are right, it is the movie length. It is shown as hours:minutes:seconds, for example 2:26:24. Now suggest a better name for result. Which name would tell a reader what it holds?
There was a problem hiding this comment.
Good name. One small thing: variable names start with a small letter, so movieDuration.
|
|
||
| // To begin, we can start with | ||
| // 1. const penceString = "399p": initialises a string variable with the value "399p" | ||
| // 2. const penceStringWithoutTrailingP = penceString.substring(0): sets penceStringWithoutTRailingP = 399.0 - penceString -1 = 39 |
There was a problem hiding this comment.
substring(0, penceString.length - 1) keeps every character except the last one. So from "399p", what is left? Log penceStringWithoutTrailingP to check.
There was a problem hiding this comment.
Right, the p is dropped. Please delete the old step 2 above it, the line that ends with = 39.
| // 2. const penceStringWithoutTrailingP = penceString.substring(0): sets penceStringWithoutTRailingP = 399.0 - penceString -1 = 39 | ||
| // 3. const paddedPenceNumberString - ensures the figure is 3 characters to taking us back to 399 | ||
| // 4 const pounds - removes 2 characters from the amount = 3 | ||
| // 5. const pence - adds the amount by 2 characters taking us back to either 39 or 99 |
There was a problem hiding this comment.
substring(paddedPenceNumberString.length - 2) takes the last two characters. From "399", which two are they? padEnd(2, "0") only adds zeros when the string is shorter than 2.
There was a problem hiding this comment.
"99" is right. But padEnd does not add anything here. Here is why:
substring(paddedPenceNumberString.length - 2)takes the last two characters of"399". That gives"99".padEnd(2, "0")adds zeros only when the string is shorter than 2 characters."99"already has 2 characters, so nothing is added.
Please update your step 5 to say this in your own words. Also delete the old step 5 above it, the line that starts // 5. const pence - adds the amount by 2 characters.
abdishakoor-dev
left a comment
There was a problem hiding this comment.
You fixed a lot this time, thanks. 1.js runs now, and your answers to b), c) and e) in 2-time-format.js are right.
You are very close. I want you to finish this and move on to the next sprint. So in each reply below, I have written exactly what to change. Please read each reply, make the change, and then push.
Here is the list:
-
3.js: lines 1 and 2. My reply has the two lines to use. -
4-random.js: change step 1 and add a step 5. My reply has the text. -
1-percentage-change.jsa): two line numbers. -
3-to-pounds.jsstep 5: whatpadEnddoes here. -
Delete three old answers. When you update an answer, you can delete the old one. Git keeps the old version for you. Delete these lines:
2-time-format.js:// It means 60 % remainder of Movie length3-to-pounds.js: the old step 2, which ends with= 393-to-pounds.js: the old step 5, which starts// 5. const pence - adds the amount by 2 characters
-
Prettier. Six files are not formatted yet:
1-count.js,2-initials.js,3-paths.js,4-random.js,0.jsand2.js. For each file:- Open the file in VS Code.
- Right click anywhere in the code.
- Choose Format Document. If VS Code asks which formatter to use, choose Prettier.
- Save the file with
Ctrl + S.
When all six are done, commit and push. To make VS Code do this 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.
abdishakoor-dev
left a comment
There was a problem hiding this comment.
You made every change on the list. All your files run, and Prettier passes on all of them.
Well done for sticking with this. Marking this Complete.

Learners, PR Template
Self checklist
Task code
CYF-1039
Changelist
24/09 - Updated files as per review instructions
24/09 - Corrected issues raised by the reviewer
I have updated and committed files in Sprint 2 - Key exercises, mandatory errors and mandatory interpret folders