Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const plantNeedsWater = function (day) { //define a function inside an expression without a function name
- if (day === "Wednesday"){
- return true; //inside the function we return the result instead, as we might not want to print eg. addition but we want to print the result of doing addition on variable 1 and 2
- }
- else {
- return false; //usually a function shouldn’t print anything and instead return a value
- }
- }
- console.log(plantNeedsWater('Tuesday')); //hence when we call the function, we will then decide what to do with the value eg. print it
- /*
- For arrow function, remove the function keyword and add in arrow after the parameter
- const plantNeedsWater = (day) => {
- if (day === 'Wednesday') {
- return true;
- } else {
- return false;
- }
- };
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement