Link to home
Start Free TrialLog in
Avatar of OMIED BADR
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!";
Avatar of Terry Woods
Terry Woods
Flag of New Zealand image

Is this a homework question?

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:
return (a==b?"same":"different");

Open in new window

Avatar of OMIED BADR
OMIED BADR

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
Avatar of Terry Woods
Terry Woods
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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)
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
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
yes problem was solved sorry saw your comment late close it thank you so much.