Hi ! I’m trying to make this funtion print a result but I can’t . I know I’m doing sth wrong but can’t see what. Would you help me ? Thks in advance
Can you please put the course link in the body of the post rather than the title of the post?
Also, please post your formatted code.
Yes,
As for the title, I’ll bear it in mind for the next question since I can’t change it now. As for the formatted code, Hope this is what you mean, thks in advance!
https://www.codecademy.com/courses/introduction-to-javascript/lessons/functions/exercises/concise-body-arrow
Please paste your (formatted) code so others can see the issues and try to help.
https://www.codecademy.com/courses/introduction-to-javascript/lessons/functions/exercises/concise-body-arrow
This is the link the code. I’ll try to copy it below, hope it helps. thks!
const plantNeedsWater = (day) => (day === “Wednesday” ? true : false);
day = “Fri”;
return plantNeedsWater();
console.log(plantNeedsWater);
Using pre-formatted code in the forums will allow others to more easily read it and provide assistance. You can do this by wrapping any code blocks in three back-ticks (```).
Remember that two of the main points of concise arrow notation are that if your function’s body is a single line, you do not need to include the brackets {} or the return keyword, though it will behave as if they were there. So,
const plantNeedsWater = day => day === "Wednesday" ? true : false;
is the same as,
const plantNeedsWater = day => {
return day === "Wednesday" ? true : false;
}
which written as a normal function expression with if/else logic instead of using ternary operators is,
const plantNeedsWater = function(day) {
if (day === "Wednesday") {
return true;
} else {
return false;
}
I’m not really sure what you’re trying to do with your next two lines. The function plantNeedsWater has one argument, the day, that needs to be passed in when called for it to function as intended. You could do so by declaring a new variable or not. So,
let day = "Friday";
console.log(plantNeedsWater(day));
or,
console.log(plantNeedsWater("Friday"));
Note that the ‘day’ inside the function and the ‘day’ outside the function are not the same (they have different scopes). Hope this helps.