London | 26-ITP-Sep | Alan Mak | Sprint 2 | Coursework - #1570
AlanGit-debug2604 wants to merge 24 commits into
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 3-paths.js works for any file name, because you used lastIndexOf for ext too. Every file runs with no errors.
Some answers are missing or need another look before I can mark this Complete:
-
1-key-exercises/1-count.jshas no answer yet. Describe what line 3 is doing, and what=does there. -
1-key-exercises/4-random.jsline 16: say whatnumis at the end. See my comment. -
2-mandatory-errors/2.js,3.jsand4.js: add the name of the error.2.jsand3.jsneed a little more too. See my comments. -
Delete the old code you commented out:
1.jslines 6 and 7,2.jslines 8 and 9,4.jslines 1 and 2, and1-percentage-change.jsline 5. Git keeps the old version for you. Keep your explanations. -
3-mandatory-interpret/1-percentage-change.js: the line numbers in a) to d), and answer e). See my comments. -
3-mandatory-interpret/2-time-format.jsanswer f): try more values. See my comment. -
3-mandatory-interpret/3-to-pounds.jsline 17. See my comment. -
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 sets spacing and indentation to one agreed style. Then a reviewer only sees the changes you meant to make. At the moment 12 of your 13 files fail that check.
Your files also have Windows line endings. So GitHub shows every line as changed, even lines you did not touch. Prettier fixes this too.
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.
| // The value inside Math.floor() is its argument. The return value of this argument is expression within the yellow parenthesis. | ||
| // The whole expression of variable "num" is that a float generated by method Math.random() is multiplied by return value of the range specified by value between declared variable by key word constant. | ||
| // The method Math.floor() then return greatest integer of the value of this product. | ||
| // And finally plus the value of minimum variable declared. |
There was a problem hiding this comment.
Your steps are in the right order. Now finish with what num is. What is the smallest value it can be? What is the largest? Run the file a few times to check.
There was a problem hiding this comment.
num is a random integer between maximum and minimum inclusive.
The smallest value of 'num' can be 1
There was a problem hiding this comment.
Done. Lines 18 and 19 say what num is.
|
|
||
| //console.log(`I was born in ${cityOfBirth}`); | ||
| //const cityOfBirth = "Bolton"; | ||
| //The error is that the variable should be declared as a constant before it is used in the console.log statement. |
There was a problem hiding this comment.
The order is the problem, you are right. Does it need to be a constant, though? Would line 4 still work with let instead of const?
The prep shows three error names: SyntaxError, TypeError and ReferenceError. Which one is this?
There was a problem hiding this comment.
This is a ReferenceError.
In this code, the key word does not need to be constant, it can be let - if this is the case the variable city0fBirth can be reassigned in other lines - instead of constant (which cannot reassign variable).
There was a problem hiding this comment.
Done. ReferenceError is right, and line 10 answers the let question.
| // Consider: Why does it give this error? Is this what I predicted? If not, what's different? | ||
| // Then try updating the expression last4Digits is assigned to, in order to get the correct value | ||
| // Expectation about the error : cardNumber is assigned a number value, a .slice function does not work on number | ||
| // The constant last4Digits should be assigned to a String (cardNumber) to perform .slice function. |
There was a problem hiding this comment.
Your prediction is clear. What happened when you ran it? Did it match your prediction?
The prep shows three error names: SyntaxError, TypeError and ReferenceError. Which one did you get?
There was a problem hiding this comment.
My very initial prediction was a last 4 card digit outcome; followed by a second glance and notice the code would result a TypeError.
There was a problem hiding this comment.
TypeError is right. Please write it in the file too, below your prediction on line 8. Did it match your prediction?
There was a problem hiding this comment.
Wrote the TypeError below my prediction line 8. Prediction matches.
There was a problem hiding this comment.
Done. Line 9 has it now.
| const 24hourClockTime = "20:53"; | ||
| // const 12HourClockTime = "8:53pm"; | ||
| // const 24hourClockTime = "20:53"; | ||
| // An identifier cannot start with a numberical value |
There was a problem hiding this comment.
Right reason. The prep shows three error names: SyntaxError, TypeError and ReferenceError. Which one is this?
There was a problem hiding this comment.
It was a SyntaxError.
There was a problem hiding this comment.
SyntaxError is right. Please add it to your comment on line 1 too.
There was a problem hiding this comment.
Thanks. Change is saved, staged, and committed.
There was a problem hiding this comment.
Done. Line 1 has it now.
| // Read the code and then answer the questions below | ||
|
|
||
| // a) How many function calls are there in this file? Write down all the lines where a function call is made | ||
| // There are five function calls in this code in lines 4, 5, and 10 |
There was a problem hiding this comment.
Your answers use the line numbers of the original file. Your file has two extra lines now. The fixed line is on line 7, and console.log is on line 12. Delete line 5 and the empty line after it. Then check your line numbers in a) to d) again.
There was a problem hiding this comment.
Line adjusted. Answers in a) to d) now correspond to the right lines.
There was a problem hiding this comment.
The line numbers are right now.
| // On lines 7 and 8, variables priceDifference and percentageChange are declared by const. | ||
|
|
||
| // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? | ||
| // To remove comma as a punctuation and space such that the string is ready turn into a number by method Number. No newline at end of file |
There was a problem hiding this comment.
Does this remove spaces too? Look at the first argument of replaceAll.
There was a problem hiding this comment.
No. replaceall("," , "") does not removes spaces. The 2nd argument is to replace each match with and empty string. Comment in code corrected accordingly - not mentioning remove spaces.
There was a problem hiding this comment.
Right. Line 33 is correct now.
| // The variable result represents length of movie in H:M:S format. A better variable name can be movieLength_HMS | ||
|
|
||
| // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer | ||
| // A value of movieLength 3661 will return a result of 1:1:1 where the place value for second does not conforms with leading zero time format. No newline at end of file |
There was a problem hiding this comment.
Good, the missing zeros are one problem. Now try -90 and 90.5. What does each one print? Would you show a time that way?
There was a problem hiding this comment.
const movieLength = -90 prints "0:-1:-30" and const movieLength = -90.5 prints "0:-1:-30.5"
The code does not work for all values:
It does not pad single digits with a leading zero;
It does not validate to reject negative or decimal input.
There was a problem hiding this comment.
Good. f) is complete now.
|
|
||
| const pence = paddedPenceNumberString | ||
| .substring(paddedPenceNumberString.length - 2) | ||
| .padEnd(2, "0"); // declares variable for pence. Argument -2 of .substring method returns the last two characters. |
There was a problem hiding this comment.
The argument here is paddedPenceNumberString.length - 2, not -2. What number is that for "399"?
There was a problem hiding this comment.
Copy that. For "399" length of 3 characters, .substring (paddedPenceNumberString.length - 2)' returns substring(1)` . Given zero indexing, therefore should return "99"
There was a problem hiding this comment.
Right, substring(1) gives "99". Lines 17 to 19 explain it well.
… 8 and 9, 4.js lines 1 and 2, and 1-percentage-change.js line 5.
abdishakoor-dev
left a comment
There was a problem hiding this comment.
Nearly there. Your answers in 1-percentage-change.js are all right now, and your answer to f) in 2-time-format.js is very thorough.
Three small things before I can mark this Complete:
3-to-pounds.jsline 1: thepis missing from"399p"now. See my comment.3.jsand4.js: you named the error in your replies. Please write it in the files too. Your answers should live in the files.- Line endings, from my last review. Your formatting is right now, thanks. But 13 of your 14 files still use Windows line endings (CRLF), so GitHub still shows every line as changed. Format Document does not change line endings. Instead, open each file in VS Code, click
CRLFin the blue bar at the bottom right, chooseLF, and save.1-count.jsis already right.
Add the Needs Review label again once you have pushed.
|
|
||
| // To begin, we can start with | ||
| // 1. const penceString = "399p": initialises a string variable with the value "399p" | ||
| const penceString = "399"; // initialises a string variable with the value "399p" |
There was a problem hiding this comment.
Line 1 was "399p" before. Now it is "399", without the p. I think this changed by accident. Run the file. It prints £0.39, not £3.99. Please put the p back.
There was a problem hiding this comment.
Thanks for reminder. Saved the change, staged, and committed the file.
There was a problem hiding this comment.
Fixed. It prints £3.99 again.
abdishakoor-dev
left a comment
There was a problem hiding this comment.
All three fixed, thanks. 3-to-pounds.js prints £3.99 again, and the error names are in 3.js and 4.js.
One last thing. 2-initials.js still has Windows line endings (CRLF). It is the only file left. Open it in VS Code, click CRLF in the blue bar at the bottom right, choose LF, and save.
Add the Needs Review label again once you have pushed, and I will mark this Complete.
abdishakoor-dev
left a comment
There was a problem hiding this comment.
All fixed. Every file uses LF now, Prettier passes, and every file runs. Marking this Complete. Well done.
Two things for your next PRs. You don't need to change anything here:
-
Variable names in JavaScript use camelCase, starting with a small letter. So in
4.js,twelveHourClockTime, notTweleveHourClockTime. Check the spelling of "twelve" too. -
You asked on Slack how to stop CRLF coming back. There are two settings:
- In VS Code, press
Ctrl + ,and search for eol. Change Files: Eol fromautoto\n. New files will then use LF. (The Prettier setting you ticked only chooses the formatter. It does not change line endings.) - In the terminal, run this once:
git config --global core.autocrlf input. Git will then change CRLF to LF every time you commit.
Please don't add a
.gitattributesfile to your coursework branch. It would be an extra file outside the Sprint-2 folder, so it would show in your PR. The two settings above fix it on your computer for every repo. - In VS Code, press

Alan Mak, PR Template
Self checklist
CYF-1039
Changelist
Work done in files in coursework, namely in folders:
1-key-exercises
2-mandatory-errors
3-mandatory-interpret and
4-stretch-explore