Everyone Can Code!

JavaScript Kata #23: Returning Strings


If you missed the introductory post, it's here. For a list of previously solved katas, please refer to the bottom of this page.

If this is your first time seeing my post, please note - these katas are probably randomly assigned per user so please don't go into Codewars thinking we will have exactly the same user experience, I am just posting these in the order that I got them.

Kata #23

DESCRIPTION:

Make a function that will return a greeting statement that uses an input; your program should return, "Hello, <name> how are you doing today?".

[Make sure you type the exact thing I wrote or the program may not execute properly]

Starting code:

function greet(name){
  //your code here
}

My attempt:

const greet = name => `Hello, ${name} how are you doing today?`

Rank #1 in 'Best Practice':

function greet(name){
  return `Hello, ${name} how are you doing today?`;
}

Rank #2:

const greet = name => `Hello, ${name} how are you doing today?`;

Rank #3:

// Return a greeting string
function greet(name) {
  return "Hello, " + name + " how are you doing today?";
}

And brace yourself for another troll in the form of user rabbit_binary7 at rank #4:

function greet(name) {
  return `\x48\x65\x6c\x6c\x6f\x2c\x20${name}\x20\x68\x6f\x77\x20\x61\x72\x65\x20\x79\x6f\x75\x20\x64\x6f\x69\x6e\x67\x20\x74\x6f\x64\x61\x79\x3f`
}

Here is a converter I found to figure out that the codes are hexadecimal, and that it's quite ironic for them because the username is literally rabbit_binary7. I'm guessing that person has so much time on their hands to type all that out if it was typed one by one. There are "text to hex" converters I found online but didn't see one that provides the escaping (\x) for JavaScript, so maybe they made their own (I think easy enough if they added to this pre-made code). The Internet is truly such a strange place.

That's it for Kata #23, stay tuned for more katas to be solved!

Link to Kata #1: Square(n) Sum

Link to Kata #2: Convert a Number to a String

Link to Kata #3: DNA to RNA Conversion

Link to Kata #4: Remove First and Last Character

Link to Kata #5: MakeUpperCase

Link to Kata #6: Total amount of points

Link to Kata #7: A Needle in the Haystack

Link to Kata #8: Sum of positive

Link to Kata #9: Basic Mathematical Operations

Link to Kata #10: Beginner - Reduce but Grow

Link to Kata #11: Square Every Digit

Link to Kata #12: Friend or Foe?

Link to Kata #13: Grasshopper - Summation

Link to Kata #14: Get the Middle Character

Link to Kata #15: Descending Order

Link to Kata #16: String ends with?

Link to Kata #17: Sum of two lowest positive integers

Link to Kata #18: Sum of odd numbers

Link to Kata #19: Find the next perfect square!

Link to Kata #20: Reversed Strings

Link to Kata #21: Jaden Casing Strings

Link to Kata #22: Even or Odd

Resources

  1. https://www.sciencebuddies.org/science-fair-projects/references/ascii-table
  2. https://www.geeksforgeeks.org/convert-a-string-to-hexadecimal-ascii-values/
  3. https://www.publish0x.com/learn-to-code-with-me/obligatory-introductory-post-xddgyxl
  4. https://www.publish0x.com/learn-to-code-with-me/javascript-kata-1-squaren-sum-xvmywpl
  5. https://www.publish0x.com/learn-to-code-with-me/javascript-kata-2-convert-a-number-to-a-string-xmymkwm
  6. https://www.publish0x.com/learn-to-code-with-me/javascript-kata-3-dna-to-rna-conversion-xgjlpox
  7. https://www.publish0x.com/learn-to-code-with-me/javascript-kata-4-remove-first-and-last-character-xyeyykj
  8. https://www.publish0x.com/learn-to-code-with-me/javascript-kata-5-makeuppercase-xzgnnqd
  9. https://www.publish0x.com/learn-to-code-with-me/javascript-kata-6-total-amount-of-points-xeellvx
  10. https://www.publish0x.com/learn-to-code-with-me/javascript-kata-7-a-needle-in-the-haystack-xlqzzgp
  11. https://www.publish0x.com/learn-to-code-with-me/javascript-kata-8-sum-of-positive-xxzyyrl
  12. https://www.publish0x.com/learn-to-code-with-me/javascript-kata-9-basic-mathematical-operations-xlqzzer
  13. https://www.publish0x.com/learn-to-code-with-me/javascript-kata-10-beginner-reduce-but-grow-xxzyylv
  14. https://www.publish0x.com/learn-to-code-with-me/javascript-kata-11-square-every-digit-xnnxxyr
  15. https://www.publish0x.com/learn-to-code-with-me/javascript-kata-12-friend-or-foe-xddggmm
  16. https://www.publish0x.com/learn-to-code-with-me/javascript-kata-13-grasshopper-summation-xnnxxwr
  17. https://www.publish0x.com/learn-to-code-with-me/javascript-kata-14-get-the-middle-character-xrgnney
  18. https://www.publish0x.com/learn-to-code-with-me/javascript-kata-15-descending-order-xmymmwn
  19. https://www.publish0x.com/learn-to-code-with-me/javascript-kata-16-string-ends-with-xeelnpk
  20. https://www.publish0x.com/learn-to-code-with-me/javascript-kata-17-sum-of-two-lowest-positive-integers-xjroxpn
  21. https://www.publish0x.com/learn-to-code-with-me/javascript-kata-18-sum-of-odd-numbers-xeelnwk
  22. https://www.publish0x.com/learn-to-code-with-me/javascript-kata-19-find-the-next-perfect-square-xozowvo
  23. https://www.publish0x.com/learn-to-code-with-me/javascript-kata-20-reversed-strings-xvmyqyn
  24. https://www.publish0x.com/learn-to-code-with-me/javascript-kata-21-jaden-casing-strings-xwywdwd
  25. https://www.publish0x.com/learn-to-code-with-me/javascript-kata-22-even-or-odd-xwywdvd

How do you rate this article?

5


YayoDrayber
YayoDrayber

A Yayo, A Drayber, among others.


Learn To Code With Me
Learn To Code With Me

Just started with Codewars and will be posting the solutions I came up with here and the apparent best practices.

Publish0x

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.