Click here to Skip to main content
15,609,864 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
function helloYou(name){


/* Do not modify code below this line */
console.(helloYou('bob'), ←- Should return undefined')
console.log(helloYou('anna'), ←- Should return " Hello, Anna!"')

What I have tried:

I have no idea where to start. I am looking for someone that can explain functions briefly and how I can make a function read how whether not a word has an even amount of characters. If the word has an odd number of letters it needs to result in " undefined " If the word has an even number of letters it needs to result in the " Hello, Anna! " You can take a look at the code above to get a better idea of what it is I am asking.
Updated 20-May-20 10:19am

This allows you to get the length of a string:
String.length - JavaScript | MDN[^]

Then you can use this little bit trick to test whether a number is odd or even:
function isOdd(n)
   return n & 1 == 1;

The rest is just a matter of an if .. else block to implement the logic.
Share this answer
jd2426 20-May-20 15:32pm    
Still semi clueless. I am new to coding. I am going to figure this out one way or another.
phil.o 20-May-20 16:00pm    
In the helloYou function:
1. Get the length of the string parameter.
2. Test whether it is odd:
2a. If it is odd, return "undefined".
2b. Else, concatenate "Hello, ", the parameter, then "!", and return the result.

There is absolutely no difficulty nor trick in that. You just have to start writing and testing.
The only cure to clueless is getting a clue - and this is the place I used to learn javaScript.[^]

They make it easy - with examples that you can modify and see what happens.

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