WM4-Kavita-Patil-JavaScript-Core-1-Coursework-Week4 - #335
Conversation
Kavita patil
fixed code for failing test cases 4-tax
|
|
||
| function getTotal(a, b) { | ||
| total = a ++ b; | ||
| total = a + b; |
There was a problem hiding this comment.
Do you remember what we need to put at the start of the line when defining or creating a new variable?
| total = a + b; | ||
|
|
||
| return "The total is total"; | ||
| return `The total is ${total}`; |
| // Add comments to explain what this function does. You're meant to use Google! | ||
| function getRandomNumber() { | ||
|
|
||
| //returns a random number between 0 (included) and 1 (excluded) and multiple by 10: |
There was a problem hiding this comment.
Do you know what kind of random number? Integer? Decimal? Negative or positive?
There was a problem hiding this comment.
It always returns a number lower than 1.
|
|
||
| function calculateSalesTax() {} | ||
| function calculateSalesTax(price) { | ||
| var salesTax = price + price * .20; |
There was a problem hiding this comment.
This confused me to begin with as to why you were multiplying the price by 0.2. One of the reasons is that I have no idea what the significance of that number is. In the industry we'd refer to this as a "magic number". It's considered better to treat it as a named constant defined somewhere in your code. Some people/organisations will capitalize shared constants, something like:
const TAX_RATE = 0.2;
function calculateSalesTax(price) {
let tax = price * TAX_RATE;
return price + tax;
}
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?
View rendered exercises/G-numbers/README.md
View rendered exercises/L-functions-nested/README.md