NW4 -Gulnihal Naldoken - JS -Week1 - #125
Conversation
zeinaji
left a comment
There was a problem hiding this comment.
Nice work Gulnihal 😊 and well done on the extensions! The logic is sound across the coursework, my only comment is to try and assign expressions to variables whenever possible just as a way of making the code easier to read
| console.log(message); | ||
| var greeting = message + firstName; | ||
|
|
||
|
|
There was a problem hiding this comment.
When leaving gaps between lines of code, it's best to go for no more than one line at a time to make things easier to read 🙂
| console.log(firstNameLength); | ||
|
|
||
| var message = "My name is Gulnihal and my name is 8 characters long" | ||
|
|
There was a problem hiding this comment.
Here you could concatenate the message variable using the other two variables, either with a plus operator + or through interpolation. So could have
var message = "My name is " + firstName + " and my name is " + firstNameLength + " characters long"
or
var message = `My name is ${firstName} and my name is ${firstNameLength} characters long`
| var numberOfStudents =30; | ||
| var numberOfMentors = 16; | ||
| var totalNumberOfStudentsAndMentors = numberOfStudents + numberOfMentors; | ||
| console.log(totalNumberOfStudentsAndMentors); No newline at end of file |
There was a problem hiding this comment.
You could also use string concatenation here to log it in this format
Number of students: 15
Number of mentors: 8
Total number of students and mentors: 23
| console.log(roughProportionStudents); | ||
|
|
||
| var proportionMentors = (numberOfMentors / (numberOfStudents + numberOfMentors)) *100; | ||
| console.log(proportionMentors); |
There was a problem hiding this comment.
Instead of using numberOfStudents + numberOfMentors twice here, you could assign it to a variable like before, so totalNumberOfStudentsAndMentors and reference that instead, it'll make the statement more concise 🙂
| function getTotal(a, b) { | ||
| total = a ++ b; | ||
| total = a + b; | ||
|
|
|
|
||
| function concatenate(firstWord, secondWord, thirdWord) { | ||
| return firstWord.concat(secondWord, thirdWord); | ||
| // Write the body of this function to concatenate three words together. |
There was a problem hiding this comment.
You can add spaces as separate strings here, for example firstWord.concat(" ", secondWord, " ", thirdWord);
|
|
||
| function convertToBRL() {} | ||
| function convertToBRL(price) { | ||
| let BrlToP = parseFloat((price *(99/100) * 5.7).toFixed(2)); |
There was a problem hiding this comment.
Because this variable won't change after being assigned it's better to use const here
There was a problem hiding this comment.
Also to make it easier to know what the numbers are for, it is better to assign them to variables. So we could have
const transactionFee = 0.01;
const exchangeRate = 5.7;
const amountAfterFee = amountInPounds * (1 - transactionFee);
This is just to help avoid 'magic numbers' https://levelup.gitconnected.com/magic-numbers-820d2d570cc5
| /* BETTER PRACTICE */ | ||
|
|
||
| let goodCode = | ||
| let goodCode = "£" + ((startingValue+10)*2); |
There was a problem hiding this comment.
It's actually the other way round here, it's better practice to use the functions, as it gives less room for error. However, you could make it more readable, because as you said it looks quite crowded. You could assign the output of each function to a variable and then reference that, it'd make it easier to read. For example:
const startingValueAddTen = add(startingValue, 10);
const multipliedByTwo = multiply(startingValueAddTen, 2);
const formattedValue = format(multipliedByTwo);
| "Concentrate and ask again.", | ||
|
|
||
| // ## Very negative | ||
| "Don't count on it.", |
There was a problem hiding this comment.
You could also have 4 different array variables here, veryPositive, positive, negative, and veryNegative and concatenating these in the answers one
| :index <10 ? "positive" | ||
| :index <15 ? "negative" | ||
| : "very negative"; | ||
|
|
There was a problem hiding this comment.
Very nice use of the ternary operator here 🙂
|
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?
What did you find hard?
What do you still not understand?
Any other notes?