JavaScript week 1 - #255
Conversation
SamanZahedi
left a comment
There was a problem hiding this comment.
Hi Maira, I have reviewed your work, very well done, great work.
| // const greeting = createLongGreeting("Daniel", 30); | ||
| function createLongGreeting(name, age){ | ||
|
|
||
| return `Hello, my name is ${name} and I'm ${age} years old`; |
There was a problem hiding this comment.
Great use of concat and interpolation overall, the best option
| } | ||
|
|
||
| function concatenate(firstWord, secondWord, thirdWord) { | ||
| return firstWord + " " + secondWord + " " + thirdWord; |
There was a problem hiding this comment.
There is another way of doing this if you follow the link above
| function calculateSalesTax() {} | ||
|
|
||
| function calculateSalesTax(price) { | ||
| let totalPrice = price * 0.2 + price; |
mahsa2
left a comment
There was a problem hiding this comment.
Well done Maira on completing this assignment, and the time you've spent on it to learn 💪 💯
| function multiply() { | ||
| function multiply(a , b) { | ||
| // Calculate the result of the function and return it | ||
| return a *b; |
| @@ -1,4 +1,7 @@ | |||
| // Declare your function first | |||
| function divide (a,b){ | |||
| return a /b; | |||
| @@ -1,7 +1,16 @@ | |||
| function halve(number) { | |||
| // complete the function here | |||
| return number/2; | |||
| const name = " Daniel "; | ||
|
|
||
| console.log(message); | ||
| let message = "My name is " + firstName + " and my name is 5 characters long"; |
There was a problem hiding this comment.
- Variable
firstNamedoesn't exist here. You need to usenameinstead. - Use a string method to calculate the length of your name rather than writing it directly here as
5. - You need to use
.trim()on the name to clear extra spacing around it. - It's almost always better to use this format for string concatinations:
Like this:
name = name.trim()
let message =`My name is ${name} and my name is ${name.length} characters long`
| // Start by creating a variables `numberOfStudents` and `numberOfMentors` | ||
| let numberOfStudents = 50; | ||
| let numberOfMentors = 20; | ||
| let result = numberOfStudents + numberOfMentors; |
There was a problem hiding this comment.
Use const when your variable value won't change at all.
Use let when the content of your variable will change later in the code.
Therefore, here you can change all the let to const.
| let newPercentageOfStudents= Math.round(percentageOfStudents); | ||
| console.log(newPercentageOfStudents); | ||
| let percentageOfMentors = numberOfMentors * 100/ total; | ||
| let newPercentageOfMentors = Math.round(percentageOfMentors); |
There was a problem hiding this comment.
Again, you can use const in this file instead of all the lets.
| function createGreeting (){ | ||
| let name = "Daniel" | ||
| let message = "hello my name is " + name; | ||
| return message |
| var greeting = createGreeting("Daniel"); | ||
| function createGreeting (){ | ||
| let name = "Daniel" | ||
| let message = "hello my name is " + name; |
There was a problem hiding this comment.
Again, this format is better to use: Hello ... ${name}
| let totalPrice2 = calculateSalesTax(17.50); | ||
| console.log(totalPrice2); | ||
| let totalPrice3 = calculateSalesTax(34); | ||
| console.log(totalPrice3); |
There was a problem hiding this comment.
We don't want to keep any debugging code in our tests. We should remove all the console.logs from our test files.
The tests furthur in the file will correctly evaluate the tests.
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?multiply divide exercises
What did you find hard? nested functions and how to use terminal
What do you still not understand? need more practice
Any other notes?