London 9 - Karleen Richards - Javascript - Core 1 - Coursework - Week 1 - #451
London 9 - Karleen Richards - Javascript - Core 1 - Coursework - Week 1#451karleenmsrichards wants to merge 7 commits into
Conversation
| function add() { | ||
|
|
||
| function add(a,b) { | ||
| return +(a + b).toFixed(1); |
There was a problem hiding this comment.
Great job!
I think the task was to give the total No 2 decimals .toFixed(2)
There was a problem hiding this comment.
Hi hi, thank you. But my interpretation of this test: "test("add function - case 2 works", () => {
expect(add(2.4, 5)).toEqual(7.4);
})" is that I should ensure that there is one decimal place and not 2 for example if I use .toFixed(2) as you suggested, my answer may end up like 7.40 instead of 7.4 as an example left in the test.
I could be wrong but that is how I looked at it.
Also if I did not put .toFixed(1) I would get the recommended 7.4 and 10.1 but again I am not too sure what they expected hence I added .toFixed(1)
PeteLindsell
left a comment
There was a problem hiding this comment.
Well done on getting through the mandatory tasks and onto some of the extra tasks!
I think you may have missed the exercises section.
| function getTotal(a, b) { | ||
| total = a ++ b; | ||
|
|
||
| return "The total is total"; | ||
| a = 23; | ||
| b = 5; | ||
| return "The total is " + (a + b); | ||
| } |
There was a problem hiding this comment.
This wants to be something like the following:
function getTotal(a, b) {
const total = a + b;
return "The total is total " + total;
}
By reassigning a and b in the function means you are throwing away the values being passed in
| function introduceMe(name, age) { | ||
| name = "Sonjide"; | ||
| age = 27; | ||
| return "Hello, my name is " + name + " and I am " + age + " years old"; | ||
| } |
There was a problem hiding this comment.
the return string is correct but you dont want to reassign name and age to static values otherwise this function cant be used fore anyone that is not called Sonjide and happens to be 27 years old
| let first = startingValue + 10; | ||
| let second = first * 2; | ||
| let goodCode = format(second); |
| function addTaxAndFormatCurrency(b) { | ||
| return "£" + ((20 / 100 * b) + b).toFixed(2); | ||
| } |
There was a problem hiding this comment.
Good use of .toFixed()
(20 / 100 * b) + b can be written as b * 1.2 but your version is better when the percentage is being passed in as a value eg 20
There was a problem hiding this comment.
Hi Pete, I'm not sure if I understand what you mean. Can you please explain this more. Should I change it to b * 1.2?
|
Thank you Pete. I have made the necessary adjustments apart from the one that I need clarification on. Also I did the exercises since September they are probably in another repo. I will sort it out and get back to you. Thanks much. |
Volunteers: Are you marking this coursework? You can find a guide on how to mark this coursework in
HOW_TO_MARK.mdin the root of this repositoryYour Details
Homework Details
Notes
What did you find easy?
What did you find hard?
What do you still not understand?
Any other notes?