Click here to Skip to main content
16,015,531 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Can i have you help, please for this task ?

I have to create a function greetingTemp(greeting), where the parameter is greeting text like : Good morning, Good evening etc
Function greetingTemp return a nested function greetingPers(name). The func take 1 paramether - persons name and has to output greeting like : Good Morning,Leo!

I have to declarate 2 var one for good morning and one for Good evening with values ​​the results of calling greetingTemp() with the corresponding parameter

This is my code:

function greetingTemp(greeting){
    console.log("Good morning, " + greeting + "!")

    function greetingPers(name){
        return `${greeting}, ${name}`
    }

    return greetingPers 

}

let gm = greetingTemp("jordan") // for good morning


Im sure this code is correct, but i didnt understand also how this can be done

declarate 2 var one for good morning and one for Good evening with values ​​the results of calling greetingTemp() with the corresponding parameter

What I have tried:

function greetingTemp(greeting){
    console.log("Good morning, " + greeting + "!")

    function greetingPers(name){
        return `${greeting}, ${name}`
    }

    return greetingPers 

}


Im not sure how to present in the code this good morning and good evening
Posted
Updated 6-Oct-22 4:50am
Comments
Richard Deeming 6-Oct-22 10:41am    
const goodMorning = greetingTemp("Good morning");
const goodEvening = ... surely you can fill in the blanks here? ...

1 solution

You need to select the greeting based on the time of day, something like:
JavaScript
function greetingTemp(name) {
  let hour = new Date().getHours();
  greeting = 'morning';
  if (hour > 11) {
    greeting = 'evening'
  }
  function greetingPers(pname) {
    return `Good ${greeting}, ${pname}`;
  }
  console.log(greetingPers(name));
  return greetingPers(name);
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900