London Class 7 - Yasemin Bayraktutan-JavaScript Core 1- Week 1 - #35
London Class 7 - Yasemin Bayraktutan-JavaScript Core 1- Week 1#35ybayraktutan wants to merge 3 commits into
Conversation
exercises and mandatory completed
| return message; | ||
| } | ||
|
|
||
| console.log (createShoutyGreeting("Daniel")); |
There was a problem hiding this comment.
Hi Yasemin, It would be better to use variable names as the function parameter in console.log
your code is nicely indented. well done
There was a problem hiding this comment.
Thank you very much. I have changed this.
| // Write your function here | ||
| function createGreeting(firstName) { | ||
| var message = "Hello, my name is " + firstName; | ||
| return message; |
There was a problem hiding this comment.
For functions that are small and only do one operation (such as this one that does a string concatenation), you don't need to assign it to a variable first. You can just return the statement from the function. It's a bit cleaner and easier to read.
E.g.
function createGreeting(firstName) {
return "Hello, my name is " + firstName;
}
| // Declare your function here | ||
| function createLongGreeting (firstName, age) { | ||
| let message = "Hello, my name is " + firstName + " and I'm " + age + " years old"; | ||
| return message; |
There was a problem hiding this comment.
I would avoid assigning the variable here and just return the statement directly.
| @@ -1,7 +1,7 @@ | |||
| function halve(number) { | |||
| // complete the function here | |||
| return number/2; | |||
There was a problem hiding this comment.
It would be better if you added some spaces between the operator here, it makes it easier to read.
return number / 2
| @@ -1,7 +1,7 @@ | |||
| function triple(number) { | |||
| // complete function here | |||
| return number*3; | |||
There was a problem hiding this comment.
Same here, add spacing around the maths operators.
| function multiply() { | ||
| // Calculate the result of the function and return it | ||
| function multiply(a,b) { | ||
| return a*b; |
There was a problem hiding this comment.
Same here, add spacing around the maths operators.
| var mentor2 = "Irina"; | ||
| var mentor3 = "Mimi"; | ||
| var mentor4 = "Rob"; | ||
| var mentor5 = "Yohannes"; |
There was a problem hiding this comment.
Is this code from a different exercise? 🤔
| total = a ++ b; | ||
|
|
||
| return "The total is total" | ||
| let total = a + b; |
There was a problem hiding this comment.
You can directly return the statement here.
| let taxedPrice = price * 120 / 100; | ||
| return taxedPrice; | ||
| } | ||
|
|
There was a problem hiding this comment.
Based on the name of this function calculateSalesTax, I would expect that it would return the amount of sales tax for the item, not the cost of the item including sales tax. If I wanted the cost of the item with tax, i'd probably name it `calculatePriceWithTax'.
The names of the function should indicate what it does. You can use this as a clue to what you should write.
| @@ -17,7 +20,10 @@ function calculateSalesTax() {} | |||
| Remember that the prices must include the sales tax (hint: you already wrote a function for this!) | |||
| */ | |||
There was a problem hiding this comment.
Note the hint here, it says you already created a function that calculates the sales tax.
So in the function addTaxAndFormatCurrency we want you to use the function calculateSalesTax to calculate what the new price should be.
Again, look at the name of the function, it gives you a clue to what the logic should be.
|
You've done a great job Yasemin! 👍 You are very good at giving your variables a meaningful name and indent your functions well. My top tips would be to make sure you are consistent with the way you write your functions (always add spacing around mathematical operators and return simple statements directly from functions). You've done this in some of the files but not others. Also, pay attention to the names of functions. They will give you hints for what the function should do. Take a look at the comments I added to the |
|
Your coursework submission has been closed because nobody has interacted with it in six weeks. You are welcome to re-open it to get more feedback. |
exercises and mandatory completed
Your Details
Homework Details