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.
Nearly all of this is right. Your answers in the key-errors, debug and time-format files are all correct, and toUpperSnakeCase is a clear name.
One thing before I can mark this Complete:
3-to-pounds.js: see my comment on line 7.
Add the Needs Review label again once you've pushed.
| // You will need to declare a function called toPounds with an appropriately named parameter. | ||
|
|
||
| // You should call this function a number of times to check it works for different inputs | ||
| function toPounds(pence) { |
There was a problem hiding this comment.
Your function works for numbers, but it is not the program this exercise asks for.
The exercise wants you to take the program in Sprint-2/3-mandatory-interpret/3-to-pounds.js and turn it into a function. That program:
- takes a string like
"399p" - gives back a string like
"£3.99"
Your function takes a number, like 250, and gives back a number, 2.5. A price should show as £2.50.
Please open that Sprint 2 file. Put its code inside your toPounds function, and use the parameter in place of "399p". Then call the function with a few different inputs, for example "399p", "5p" and "2500p".
There was a problem hiding this comment.
Your function works now. A string goes in, and a string comes out. Good.
But this exercise had a different aim. The Sprint 2 code in Sprint-2/3-mandatory-interpret/3-to-pounds.js already changes pence to pounds, and it works. But it only works for one price, because "399p" is fixed on line 1. To change "5p" or "2500p", you would need to copy all the lines again.
A function solves this. When we need the same lines many times, we put them in a function. The part that changes each time becomes the parameter. Here, the part that changes is the pence amount. The steps stay the same.
So you did not need to write new steps. Your three lines do the same jobs as the Sprint 2 lines:
| Job | Your code | Sprint 2 code |
|---|---|---|
Remove the p |
line 8: Number(pence.replace("p", "")) |
lines 3 to 6: penceString.substring(...) |
| Split into pounds and pence | line 9: penceNumber / 100 |
lines 8 to 16: padStart, substring, padEnd |
| Build the price | line 10: `£${pounds.toFixed(2)}` |
line 18: `£${pounds}.${pence}` |
You only needed to change two Sprint 2 lines:
- Sprint 2 line 1,
const penceString = "399p";, goes away. The parameter takes its place. If you call the parameterpenceString, lines 3 to 16 work with no changes at all. - Sprint 2 line 18 uses
console.log. In a function, change it toreturn.
The function looks like this:
function toPounds(penceString) {
// Sprint 2 lines 3 to 16 go here, with no changes
return `£${pounds}.${pence}`;
}Now the same lines work for every price. toPounds("399p"), toPounds("5p") and toPounds("2500p") all use them. Only the value you pass in changes.
The rule: if you need the same lines many times, put them in a function. Make the part that changes a parameter.
|
@abdishakoor-dev Thank you for your comment. I have made the changes |
abdishakoor-dev
left a comment
There was a problem hiding this comment.
Thanks. toPounds works now, so I'm marking this Complete. Please read my reply on line 7. It explains the aim of this exercise.

Learners, PR Template
Self checklist
Task code
CYF-1053
Changelist
Completed the Sprint 3 JavaScript Fundamentals coursework, including debugging, implementation, code interpretation, and stretch exercises.