NW6| FIDAA BASHIR | Module-JS1 | WEEK2#179
NW6| FIDAA BASHIR | Module-JS1 | WEEK2#179Fidaabashir89 wants to merge 10 commits intoCodeYourFuture:mainfrom
Conversation
|
|
||
| console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); | ||
|
|
||
| //The first line of the function logs the product of the two arguments to the console. The second line of the code calls the multiply() function with the arguments 10 and 32, and then logs the result to the console. The expected output is: |
|
|
||
| console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); | ||
|
|
||
| //the error here that we should place the a + b expression directly after the return keyword. No newline at end of file |
There was a problem hiding this comment.
This is true, I would probably word it a bit differently - the problem is that the function returns nothing - the line below return is never executed.
| function getLastDigit() { | ||
| return num.toString().slice(-1); | ||
| function getLastDigit(num) { | ||
| return num % 10; |
There was a problem hiding this comment.
This is a clever solution. No one else I've seen has done this. It does have a small bug, though, if we change the inputs a bit. Also if possible some more explanation would be great
|
|
||
| function capitalise(str) { | ||
| let str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| str = `${str[0].toUpperCase()}${str.slice(1)}`; |
| // Why will an error occur when this program runs? | ||
| // Play computer with the example to work out what is going on | ||
| //In this code, there is an error that the variable decimalNumber, declared twice. once as a parameter of the convertToPercentage function and again outside the function, because in JS variables can't be declared twice within the same scope | ||
| // to fix this error, we need to delete the parameter in line 8, so we can call the function without any argument. |
|
|
||
| function calculateBMI(weight, height) { | ||
| const BMI = weight / (height * height); | ||
| return BMI.toFixed(1); | ||
|
|
||
| } |
| // Come up with a clear, simple name for the function | ||
| // Use the string documentation to help you plan your solution | ||
|
|
||
| function camelCaseToWords(text) { |
There was a problem hiding this comment.
This is a great little function, well done. For next time, I'd probably name it differently, functions rend to get named something g like convertToUpperCamelCase() but this is a mere niggle
|
|
||
| function toPounds(penceString) { | ||
| const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1); | ||
| const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); | ||
| const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2); | ||
| const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"); | ||
| return `£${pounds}.${pence}`; | ||
| } |
There was a problem hiding this comment.
Looking good, appreciate the descriptive var names!
| // Then it returns the new price with VAT added on | ||
|
|
||
| function calculatePriceWithVAT(price) { | ||
| price = price * 1.2; |
There was a problem hiding this comment.
Works, Could just do return price * 1.2; here - this line isn't strictly necessary
| //we can use padStart(2, '0') to pad the numbers to a length of two characters with the padding character '0'. like this: | ||
| //function pad(num) { | ||
| //return num.toString().padStart(2, '0'); | ||
| //} No newline at end of file |
There was a problem hiding this comment.
All amazing here no faults that I can find, well done 👏
Learners, PR Template
Self checklist
Changelist
Briefly explain your PR.
I worked on the JS1 module exercises
Questions
Ask any questions you have for your reviewer.