WM4-Azin Yadegari-JavaScript-Core-1-Coursework-Week1#326
Conversation
| // Declare your function here | ||
|
|
||
| function createLongGreeting(name,age){ | ||
| return `Hello, my name is ${name} and I'm ${age} years old`; |
|
@jdbevan sorry Jon I couldn't find a proper way to add you as a reviewer for this week assignment ,that I created a pull request few days a go |
| @@ -1,3 +1,6 @@ | |||
| const name = " Daniel "; | |||
|
|
|||
| const message=`My name is Daniel and my name is 6 characters long`; | |||
There was a problem hiding this comment.
Your code should be more versatile if you use variable instead of 'Daniel' and - name.length instead of '6'
| var studentsPercentage=Math.round( (numberOfStudents/total)*100); | ||
| var mentorsPercentage=Math.round( (numberOfMentors/total)*100); | ||
| console.log(`Percentage students: ${studentsPercentage} % | ||
| \n Percentage mentors: ${mentorsPercentage} % `); |
| //missing let & extra + | ||
|
|
||
| return "The total is total"; | ||
| return `The total is ${total}`; |
| // Add comments to explain what this function does. You're meant to use Google! | ||
| function getRandomNumber() { | ||
| return Math.random() * 10; | ||
| return Math.random() * 10; //The Math. random() function returns a floating-point, pseudo-random number in the range 0 to less than 1 (inclusive of 0, but not 1) with approximately uniform distribution over that range |
There was a problem hiding this comment.
This is a great copy/paste from MDN Web Docs :) what's a floating-point, pseudo-random number?
There was a problem hiding this comment.
you are right , as it says we meant to google it , I just copy paste what I found and have no idea what that means :)) I eaven searched the meaning of it now and it got harder to understand ,I believe that Math.random() will return a number between 0 and 1 , I think it could include 0 but not the 1
There was a problem hiding this comment.
Nice! Any idea what kind of number? Positive? Negative? Decimal? Something else?
| // Add comments to explain what this function does. You're meant to use Google! | ||
| function combine2Words(word1, word2) { | ||
| return word1.concat(word2); | ||
| return word1.concat(word2); //The concat() method is used to merge two or more arrays. This method does not change the existing arrays, but instead returns a new array. |
There was a problem hiding this comment.
Are you sure this function is dealing with arrays?
There was a problem hiding this comment.
Thanks for mentioning it leaded me to testing it , and it works for merging arrays, but t also works for merging strings ,there will be no space between merged strings though.
| // 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.
This isn't wrong, but I'm curious why you chose to use a mixture of .concat() and then also string templating?
There was a problem hiding this comment.
good point, to be honest I have no idea either . I could have done it by adding .concat() twice as well.
|
|
||
| function calculateSalesTax() {} | ||
| function calculateSalesTax(price) { | ||
| return price+(price*20)/100 |
There was a problem hiding this comment.
This confused me to begin with as to why you were multiplying the price by 20. One of the reasons is that I have no idea what the significance of that number is. In the industry we'd refer to this as a "magic number". It's considered better to treat it as a named constant defined somewhere in your code. Some people/organisations will capitalize shared constants, something like:
const TAX_RATE = 20;
function calculateSalesTax(price) {
let tax = price * TAX_RATE / 100;
return price + tax;
}
There was a problem hiding this comment.
yes you are totally right and your suggested solution is far better , I will keep it in mind and use this from now on.Thanks Jon.
Co-authored-by: Jon Bevan <jon@jdbevan.com>
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?
View rendered exercises/L-functions-nested/README.md