OMIED BADR
asked on
JavaScript problem
I'm having issues with the problem below. It's telling me to Use the conditional operator to rewrite the if...else statement in the editor. on the very bottom is my answer and the beginning part is where we to take the problem and rewrite it. please help.
function greet(hour) {
if (hour < 12) {
return "Good morning!";
} else {
return "Good afternoon!";
}
}
var greet = greet(hour);
greet() = (hour < 12) ? "Good morning!" : "Good afternoon!";
function greet(hour) {
if (hour < 12) {
return "Good morning!";
} else {
return "Good afternoon!";
}
}
var greet = greet(hour);
greet() = (hour < 12) ? "Good morning!" : "Good afternoon!";
ASKER
no its part of a bootcamp and the instructor are too busy to help that is why I asked the problem.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
when I use your solution below are the errors messages I get.
greet is defined and is a function
expected 'Good afternoon!' to be a function
returns "Good morning!" if the hour is before noon
TypeError: greet is not a function at Context.<anonymous> (decoded.txt:24:12)
returns "Good afternoon!" if hour is after noon
TypeError: greet is not a function at Context.<anonymous> (decoded.txt:28:12)
greet is defined and is a function
expected 'Good afternoon!' to be a function
returns "Good morning!" if the hour is before noon
TypeError: greet is not a function at Context.<anonymous> (decoded.txt:24:12)
returns "Good afternoon!" if hour is after noon
TypeError: greet is not a function at Context.<anonymous> (decoded.txt:28:12)
ASKER
I took out var greet = greet(hour); out of the code you gave me and it worked it was correct thank you for all your help.
No probs... don't forget to close the question :-)
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
yes problem was solved sorry saw your comment late close it thank you so much.
Do you still need to keep your code wrapped in the greet function? If so, then you'd just remove the if else part of the function and replace it with your code, but you will need to edit your code to actually return the result.
You can return a result a bit like this:
Open in new window