NorthWest_4 - Dharma_Guadeloupe - JavaScript_Core_1_Coursework - Week_1#111
NorthWest_4 - Dharma_Guadeloupe - JavaScript_Core_1_Coursework - Week_1#111dharmaguadeloupe wants to merge 29 commits intoCodeYourFuture:masterfrom
Conversation
anthonytranDev
left a comment
There was a problem hiding this comment.
Nice work Dharma!
Some comments for you below
| @@ -0,0 +1,3 @@ | |||
| { | |||
| "editor.formatOnSave": true | |||
There was a problem hiding this comment.
Instructions Followed Incomplete (optional)
Instructions have mentioned the following Set editor.formatOnSave and editor.formatOnPaste to true
This is optional as I usually turn the latter settings off
| @@ -1,2 +1,9 @@ | |||
| var numberOfStudents = 15; | |||
There was a problem hiding this comment.
Incorrect Amount (Optional)
Isn't the correct amount of students and mentors, in your NW4 group - though will let you off. Most importantly, the core implementation is correct
| function multiply() { | ||
| function multiply(num1, num2) { | ||
| // Calculate the result of the function and return it | ||
| return num1 / num2; |
There was a problem hiding this comment.
Incorrect operator
Needs a multiplication operator - i.e. not a division operator
There was a problem hiding this comment.
oops, honest mistake. That's what I get for not reading it properly. Fixed Now. Thanks
|
|
||
| /* BETTER PRACTICE */ | ||
|
|
||
| let goodCode = |
There was a problem hiding this comment.
Ignore this exercise - there is little guidance here and both are bad practice, as you aren't making the code more readable or succinct
Answer below
// don't use somewhat useless functions, when operators do a better job (and are more readable)
const startingValue = 2
const bestCode = `${(10 + startingValue) * 2}`| Outlook not so good. | ||
| Very doubtful. | ||
| */ | ||
| **/ |
| return answerIteration < 5 ? "very positive" : answerIteration >=5 && answerIteration < 10 ? "positive" | ||
| : answerIteration >=10 && answerIteration < 15 ? "negative" : "very negative"; |
There was a problem hiding this comment.
Style
Please Never use nested ternary statements, ever
For the following multiplicity logic - not a real term, just a way I describe it.
Only use ternary for single branched out logic
For the code here, stick to using the following:
Increase in (reading) complexity the way down
- (A bunch of)
ifstatements - Then,
switchstatements (or objects - key value pairs, if you know how to use them) - Lastly,
if...elsestatements
There was a problem hiding this comment.
This was setting myself the challenge of seeing if I could convert it and understand nested ternary statements. Below is the code I used to work it out using If /else logic
| /**if(answerIteration < 5) { | ||
| return "very positive"; | ||
| } else if(answerIteration >= 5 && answerIteration < 10) { | ||
| return "positive"; | ||
| } else if(answerIteration >=10 && answerIteration < 15) { | ||
| return "negative" | ||
| } else { | ||
| return "very negative"; | ||
| }**/ | ||
|
|
There was a problem hiding this comment.
Reducing complexity
- This is actually more readable, you can try use a bunch of
ifstatements - Oh avoid multiple
returnforiforif...elsestatements, try to assign the values, so that code flow can be read more linearly - it's more a special JavaScript style
Hint:
let message;
if(answerIteration < 5 ) {
message = "very positive";
}
if(answerIteration >= 5 && answerIteration < 10 ) {
message = "positive";
}
// etc ...
return message;There was a problem hiding this comment.
That's something I've learned since, I was writing a lot of extra code that isn't actually needed. It's great to come back to this so many weeks later and see the difference between this, and how I write code now.
| } | ||
|
|
||
| let seenPositivities = new Set(Array.from(answers.values()).map(checkAnswer)); | ||
| let seenPositivities = new Set(Array.from(seenAnswers.values()).map(checkAnswer)); |
There was a problem hiding this comment.
Arghhh...
Not your code, but I hate it. No one uses new Set in the industry, this isn't super easy to read either
There was a problem hiding this comment.
That worried for a minute as I was certain I hadn't written this
| // Write the body of this function to concatenate three words together. | ||
| // Look at the test case below to understand what this function is expected to return. | ||
| return firstWord.concat(' ', secondWord, ' ', thirdWord); | ||
|
|
There was a problem hiding this comment.
Style
Remove unnecessary newline
There was a problem hiding this comment.
I'm not sure what means
| const formattedCurrency = taxCalculation + product; | ||
| const salesTaxFormatted = formattedCurrency.toFixed(2); | ||
| return `£${salesTaxFormatted}`; | ||
|
|
There was a problem hiding this comment.
Style
Same here with removing the newline
|
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. |
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? The exercises were great way to cement what I already knew
What did you find hard? Figuring out the ternary operator for the extra homework
What do you still not understand? Still a litle fuzzy on ternary's
Any other notes?
View rendered README.md
View rendered exercises/G-numbers/README.md