London | 26-ITP-Sep | Chandaramani Gaire | Sprint 2 | Sprint 2 Coursework - #1575
gaireprakash20-ops wants to merge 4 commits into
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.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
abdishakoor-dev
left a comment
There was a problem hiding this comment.
Your 1-percentage-change.js answers a) to e) are all right, and you fixed the missing comma on line 5 too. 3-paths.js also works well, because you used lastIndexOf for ext.
I have left a hint on each line. These are the things to fix before I can mark this Complete:
-
Six files stop with a SyntaxError, so none of their code runs:
0.js,1.js,2.js,4.js,1-percentage-change.jsand2-time-format.js. Each one has a comment that starts with/*but never ends. Add*/at the end of each/*comment. Then run each file with node to check. -
2-mandatory-errors: your explanations are good, but the code in1.js,2.js,3.jsand4.jsstill fails. Fix each one so it runs with no error. -
2-initials.jslines 4 and 8. -
4-random.jsline 13: finish the breakdown. -
2-time-format.js: answers c), d) 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 most of your files 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
Fix point 1 first. Prettier cannot format a file that has a SyntaxError.
Add the Needs Review label again once you have pushed.
| We don't want the computer to run these 2 lines - how can we solve this problem? No newline at end of file | ||
| /*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? | ||
| for single line we used // and for multiple line use /* No newline at end of file |
There was a problem hiding this comment.
Your idea is right. /* starts a comment over many lines. But a /* comment must also end, with */. Add */ at the end of line 3.
Then run node 0.js. It should print nothing and show no error. Five more files have the same problem.
| const middleName = "Katherine"; | ||
| const lastName = "Johnson"; | ||
|
|
||
| const CKJ = "something" |
There was a problem hiding this comment.
The task says you must not write C, K or J in your code. Line 4 has all three. Line 4 is not used anywhere, so you can delete it.
| const initials = ``; | ||
|
|
||
| // https://www.google.com/search?q=get+first+character+of+string+mdn | ||
| const initials = `"${firstName.charAt(0)}${middleName.charAt(0)}${lastName.charAt(0)}"`; |
There was a problem hiding this comment.
Run the file. It prints "CKJ", with quote marks. The task wants CKJ. The quote marks come from the two " inside your backticks. What happens if you delete them?
|
|
||
| // In this exercise, num represent the value integer number between 1 to 100. | ||
| //Math.random generates a random decimal number from 0 up to 1, but not including, 1. | ||
| // down to the nearest whole number (integer). |
There was a problem hiding this comment.
Line 13 starts in the middle of a sentence. I think it is about Math.floor. Please finish it.
Two steps are also missing. Math.random() * (maximum - minimum + 1) is Math.random() * 100. That gives a decimal from 0 up to 100. Math.floor then makes it a whole number from 0 to 99. So what does + minimum do at the end?
| age = age + 1; | ||
|
|
||
| /* In this case age is not const means variable is not reassigned so that, | ||
| we throws a TypeError: Assignment to constant variable.2 |
There was a problem hiding this comment.
You found the right message: TypeError: Assignment to constant variable. But the file still stops with that error. Which keyword lets you give a variable a new value later? Use it on line 3.
| @@ -1,9 +1,12 @@ | |||
| const cardNumber = 4533787178994213; | |||
| const last4Digits = cardNumber.slice(-4); | |||
| const last4Digits = string(cardNumber).slice(-4); | |||
There was a problem hiding this comment.
Your prediction on line 11 is right. Now run node 3.js. It stops with a new error: ReferenceError: string is not defined. In JavaScript, capital letters matter in names. Is string the same as String?
| @@ -1,2 +1,3 @@ | |||
| const 12HourClockTime = "8:53pm"; | |||
| const 24hourClockTime = "20:53"; | |||
| /*variable is not start with number show syntaxerror. | |||
There was a problem hiding this comment.
Your reason is right. A variable name cannot start with a number. Now rename the two variables on lines 1 and 2, so the file runs. For example, you can move the number to the end of the name, or write it as a word.
|
|
||
| // c) Using documentation, explain what the expression movieLength % 60 represents | ||
| // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators | ||
| /*The remainder (%) operator returns the remainder left over when one operand is divided by a second operand. It always takes the sign of the dividend. |
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 in this program.
| /*The remainder (%) operator returns the remainder left over when one operand is divided by a second operand. It always takes the sign of the dividend. | ||
|
|
||
| // d) Interpret line 4, what does the expression assigned to totalMinutes mean? | ||
| /* This expression convert movies time second into minutes dividend by 60 second. |
There was a problem hiding this comment.
Dividing by 60 is the second step. First, (movieLength - remainingSeconds) takes the 24 leftover seconds away. Why do that before dividing by 60? Try 8784 / 60 in node and look at the result.
| We can change this name as movieTime. | ||
|
|
||
| // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer | ||
| /* In this section we can only use the positive natural numbers but if we put numbers that divide by 60 without a remainder get the exact time like 10, 20 50. |
There was a problem hiding this comment.
You are right that positive whole numbers work. Now try -90 and 90.5 as movieLength. What does the program print each time? Would you show a time like that? Write what you see.
Also, 10, 20 and 50 cannot be divided by 60 with no remainder. Which numbers can?

Self checklist
Task code
CYF-1039
Changelist
Answer the question and make changes per the question's requirements.