London_10-Anna_Hrychaniuk-JS-Core-1-Week1 - #495
Conversation
| const allAnswers = ["very positive", "positive", "negative", "very negative"]; | ||
| let answer = allAnswers [Math.floor(Math.random()*allAnswers.length)]; | ||
| // console.log(prediction); | ||
| return answer; |
There was a problem hiding this comment.
| const allAnswers = ["very positive", "positive", "negative", "very negative"]; | |
| let answer = allAnswers [Math.floor(Math.random()*allAnswers.length)]; | |
| // console.log(prediction); | |
| return answer; | |
| const allAnswers = [...veryPositive, ...positive, ...negative, ...veryNegative]; | |
| let answer = allAnswers[Math.floor(Math.random()*allAnswers.length)]; | |
| return answer; |
Have a look at spread operator and try to remove unnecessary comments.
| if (veryPositive.indexOf(answer) >= 0 ) { | ||
| console.log("very positive"); | ||
| //Write your code in here | ||
| } else if (positive.indexOf(answer) >= 0) { | ||
| console.log("positive"); | ||
| } else if (negative.indexOf(answer) >= 0) { | ||
| console.log("negative"); | ||
| } else { | ||
| console.log("very negative"); | ||
| } |
There was a problem hiding this comment.
| if (veryPositive.indexOf(answer) >= 0 ) { | |
| console.log("very positive"); | |
| //Write your code in here | |
| } else if (positive.indexOf(answer) >= 0) { | |
| console.log("positive"); | |
| } else if (negative.indexOf(answer) >= 0) { | |
| console.log("negative"); | |
| } else { | |
| console.log("very negative"); | |
| } | |
| if (veryPositive.indexOf(answer) >= 0 ) { | |
| return "very positive"; | |
| } else if (positive.indexOf(answer) >= 0) { | |
| return "positive"; | |
| } else if (negative.indexOf(answer) >= 0) { | |
| return "negative"; | |
| } else { | |
| return "very negative"; | |
| } |
console.log is necessary only for developer to see what's happening. As I see you just forgot to have "return" in your loop.
| } | ||
|
|
||
|
|
||
| console.log(checkAnswer(shakeBall())); |
There was a problem hiding this comment.
| console.log(checkAnswer(shakeBall())); |
|
Good job anyway, weel done with the length. |
|
|
||
| function convertToBRL() {} | ||
| function convertToBRL(amount) { | ||
| return parseFloat((amount * 0.99 * 5.7).toFixed(2)); |
There was a problem hiding this comment.
This is a clever solution and I like your use of parseFloat, well done! However, it is not that readable. Could you break it down into steps - perhaps working out the price after fee first.
Also, could you be more specific with the labelling? i.e. instead of amount, GBP
| */ | ||
|
|
||
| function convertToUSD() {} | ||
| function convertToUSD(amount) { |
There was a problem hiding this comment.
Nice! But could you be clearer with the name 'amount'?
| // There are syntax errors in this code - can you fix it to pass the tests? | ||
|
|
||
| function addNumbers(a b c) { | ||
| function addNumbers(a, b, c) { |
kjjwhitlock
left a comment
There was a problem hiding this comment.
Great work, Anna! Well done on tackling the extra challenges. I can see you're good at keeping your code tidy and have mastered string interpolation.
Try and work on breaking out your code to more digestable steps, ensuring that one line tackles one small part of the problem at a time. That way, when your future colleagues are checking your code they'll be able to understand it quickly :)
| total = a ++ b; | ||
|
|
||
| return "The total is total"; | ||
| total = a + b; |
| function multiply(a, b, c) { | ||
| a * b * c; | ||
| return; | ||
|
|
There was a problem hiding this comment.
watch this trailing space, keep it tidy :)
|
|
||
| function format() { | ||
| function format(digit) { | ||
| return `£${digit.toString()}`; |
There was a problem hiding this comment.
Nice thinking, but do you need the toString?
| function multiply() { | ||
|
|
||
| function multiply(a, b) { | ||
| return a * b; |
There was a problem hiding this comment.
Nice and tidy with spacing and semi-colon, well done :)
| let badCode = format((startingValue + 10) * 2); | ||
|
|
There was a problem hiding this comment.
Could you use all your methods in this bad code example?
| let badCode = | ||
| let badCode = format((startingValue + 10) * 2); | ||
|
|
||
| // functions are not really used, so it would work just for one case |
There was a problem hiding this comment.
The badcode is really hard to read and is doing too much on one line so is prone to bugs :)
| /* BETTER PRACTICE */ | ||
|
|
||
| let goodCode = | ||
| let goodCode = format(multiply(add(startingValue, 10), 2)); |
There was a problem hiding this comment.
Nice getting this working on one line, but good code is readable in clear steps and stages. Can you break out these functions to call them on different lines?
kjjwhitlock
left a comment
There was a problem hiding this comment.
Great work, Anna! Well done on tackling the extra challenges. I can see you're good at keeping your code tidy and have mastered string interpolation.
Try and work on breaking out your code to more digestable steps, ensuring that one line tackles one small part of the problem at a time. That way, when your future colleagues are checking your code they'll be able to understand it quickly :)
|
|
||
| function calculateSalesTax() {} | ||
| function calculateSalesTax(netPrice) { | ||
| return netPrice * 1.2; |
There was a problem hiding this comment.
I am not sure if netprice is exactly correct to pass in (as I think netprice is after tax has been removed, and this is still before) but I like how specific and readable this label is.
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?