Westmidlands-class 4-farzad-nazif- JavaScript-Core-1-Coursework-Week1 - #332
Westmidlands-class 4-farzad-nazif- JavaScript-Core-1-Coursework-Week1#332farzad-nazif wants to merge 3 commits into
Conversation
| function convertToBRL(price) { | ||
| let priceToBeConverted = 0.99*price; | ||
| let convertedPrice = priceToBeConverted * 5.7; | ||
| return parseFloat(convertedPrice.toFixed(2)); |
There was a problem hiding this comment.
Nice job with the parseFloat(). I just got to know about it from reviewing your codes... Great job Farzad!
| function getRandomNumber() { | ||
| return Math.random() * 10; | ||
| } | ||
| // Comment : math.random gives us a random number between 0 and 1. then we times it by 10, we will have a random number between 0 and 10. |
There was a problem hiding this comment.
From my findings on Google, I could be wrong though, the getRandomNumber function will generate only floating numbers between 1 - 10
There was a problem hiding this comment.
math.random() gives you a number between 0 and 1 , if you times it by 10 , then gives you 0 to 10
There was a problem hiding this comment.
"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 — which you can then scale to your desired range. "
As you can see from the description taken from MDN Docs above, math.random() will randomly generate a number between 0 and 1. After that, it will multiply a number of your choice.
| } | ||
|
|
||
| /* | ||
| =================================================== |
There was a problem hiding this comment.
Had a great time going through your codes. it gave me alternate perspectives to solve a problem!
Thumbs up Farzad!
alicagatay
left a comment
There was a problem hiding this comment.
Nice job Farzad, I really liked the way you solved some of these problems. Keep up the good work.
| function addNumbers(a b c) { | ||
| function addNumbers(a, b, c) { | ||
| return a + b + c; | ||
| } |
There was a problem hiding this comment.
Correct, as you can see, while setting up parameters in a function, you need to separate them with commas.
| return "Hello, my name is " + name "and I am " age + "years old"; | ||
| function introduceMe(name, age){ | ||
| return "Hello, my name is " + name +" and I am " + age + " years old"; | ||
| } |
There was a problem hiding this comment.
Correct, when writing JavaScript functions, you need to use curly brackets to define the inside of the function, otherwise JavaScript won't understand that part and throw an error. In addition, as you did above, you need to put the + icon between strings and variables, so that you can concatenate them.
|
|
||
| function getTotal(a, b) { | ||
| total = a ++ b; | ||
| total = a + b; |
There was a problem hiding this comment.
Don't forget the let keyword while defining a variable!
|
|
||
| return "The total is total"; | ||
| return "The total is " + total; | ||
| } |
There was a problem hiding this comment.
Another nice way of concatenating a String with a variable. In addition, you can also use String interpolation to do this.
| function trimWord(word) { | ||
| return wordtrim(); | ||
| return word.trim(); | ||
| } |
There was a problem hiding this comment.
That's right. There is no function called wordtrim() in JavaScript. We use trim() instead.
| function getRandomNumber() { | ||
| return Math.random() * 10; | ||
| } | ||
| // Comment : math.random gives us a random number between 0 and 1. then we times it by 10, we will have a random number between 0 and 10. |
There was a problem hiding this comment.
"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 — which you can then scale to your desired range. "
As you can see from the description taken from MDN Docs above, math.random() will randomly generate a number between 0 and 1. After that, it will multiply a number of your choice.
| function combine2Words(word1, word2) { | ||
| return word1.concat(word2); | ||
| } | ||
| // Comment : This functions takes 2 parametrs and append word2 to word 1 (combine) and return a new string. |
There was a problem hiding this comment.
That's correct, this function will concatenate 2 given Strings.
| let wordCombination = firstWord.concat(secondWord); | ||
| let final = wordCombination.concat(thirdWord); | ||
| return final; | ||
| } |
| function calculateSalesTax(productPrice) { | ||
| let total = productPrice + productPrice * 0.2; | ||
| return total; | ||
| } |
There was a problem hiding this comment.
That's correct, I also like the way you calculated the total value in just 1 line, nice job.
| function addTaxAndFormatCurrency(productPrice) { | ||
| let total = calculateSalesTax(productPrice); | ||
| return "£" + total.toFixed(2); | ||
| } |
There was a problem hiding this comment.
This is also correct. In addition to this way, you can also use String interpolation to concatenate a String to a variable.
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?
understanding the var and functions
What did you find hard?
the last challenge of extra folder
What do you still not understand?
Any other notes?