How can I make my sentence spell backwards in JavaScript? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How can I make my sentence spell backwards in JavaScript?

Hi. I am planning to make a code that people can reverse their own sentences (Not just the words, the spelling). However, I don't know how to code about that. The code requires an input for them to put their own sentence. Can somebody please tell me the code? Thank you! 😊

16th Nov 2017, 2:01 PM
W1LL1AM823
W1LL1AM823 - avatar
7 Answers
+ 2
Do you want sth like this: str = "Hello World"; str = str.split("").reverse().join(""); // str is now "dlroW olleH"
16th Nov 2017, 2:04 PM
Skayo
Skayo - avatar
+ 2
@Skayo Thanks for the code! 😊
16th Nov 2017, 2:05 PM
W1LL1AM823
W1LL1AM823 - avatar
+ 1
If my code helped you then please set it as accepted answer. Thank you!
16th Nov 2017, 2:08 PM
Skayo
Skayo - avatar
0
Hi Skayo! I tried copying your code but when I run the code the output reads "No output." Is there a better code for this? I would require an input. Thx! 😊
18th Nov 2017, 2:31 PM
W1LL1AM823
W1LL1AM823 - avatar
0
Oh my bad! Please replace line 2 with: str = str.split("").reverse().join("");
18th Nov 2017, 6:50 PM
Skayo
Skayo - avatar
0
Hi Skayo! The code you gave me is the same as what you said. Try with the correct one please. Thanks!
20th Dec 2017, 8:00 AM
W1LL1AM823
W1LL1AM823 - avatar
0
No I changed the other answer too you know
20th Dec 2017, 10:41 AM
Skayo
Skayo - avatar