London | 26-ITP-Jan | Angela McLeary | Sprint 2 | Coursework/sprint 2#1110
London | 26-ITP-Jan | Angela McLeary | Sprint 2 | Coursework/sprint 2#1110AngelaMcLeary wants to merge 17 commits intoCodeYourFuture:mainfrom
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
|
||
| function capitalise(str) { | ||
| let str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| str = `${str[0].toUpperCase()}${str.slice(1)}`; |
There was a problem hiding this comment.
In small examples this work, but do you think modifying function parameters is a good practice in larger codebases?
Could you rewrite this function in a way that avoids mutating the parameter entirely?
| return `${decimalNumber * 100}%`; | ||
| } | ||
|
|
||
| console.log(decimalNumber); No newline at end of file |
| //the computer reads the values in the second console.log "multiply(10, 32)" and | ||
| //the first console.log only prints the value, it does not store it. | ||
| //the second console.log outputs the template literals and undefined | ||
| // as it has no value to reach. |
There was a problem hiding this comment.
In your explanation, you mentioned that the second console.log outputs undefined 'as it has no value to reach.' You are exactly right! The technical term for this in JavaScript is an implicit return. If you don't explicitly tell a function what to return, JavaScript automatically forces it to return undefined behind the scenes. Keep up the great work!
| // So every console.log will print 3 every time. This function is not | ||
| // re-useable as it stands. |
There was a problem hiding this comment.
Good point and observation. This function is not re-useable as it stands, functions should ideally be self-contained and reusable.
| function calculateBMI(weight, height) { | ||
| // return the BMI of someone based off their weight and height | ||
| } No newline at end of file | ||
| return (weight/(Math.pow(height, 2))).toFixed(1); |
There was a problem hiding this comment.
Using .toFixed() converts your datatype to String. How might you convert that final answer back into a true Number before returning it?
You used Math.pow(height, 2) to square the height, which is 100% correct. However, modern JavaScript has a shorthand operator for exponents that makes equations look a bit cleaner.
Learners, PR Template
Self checklist
Changelist
It is about debugging and understanding how logic works.