Click here to Skip to main content
14,545,215 members
Rate this:
Please Sign up or sign in to vote.
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.
Posted
Updated 20-May-20 10:19am
v2
Rate this:
Please Sign up or sign in to vote.

Solution 1

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.
   
Comments
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.
Rate this:
Please Sign up or sign in to vote.

Solution 2

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.


   

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

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100