Reverse sentense

I was wondering using JavaScript how would you reverse this sentence

my name is kevin

so it would say

Kevin is name my
stargateatlantisAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
basicinstinctConnect With a Mentor Commented:
ok, how about this, you want to reverse a sentence using looping in js. it is homework, so i can't just give you the answer. since you are obviously studying programming you should be able to make a start... you tell me where you are stuck and i'll help you...
0
 
basicinstinctCommented:
"my name is kevin".split(" ").reverse().join(" ")
0
 
stargateatlantisAuthor Commented:
How would you do it without using split reverse join
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
basicinstinctCommented:
hmmm, why?

there are a bazillion ways you could do it. Like this for example (not using split, reverse or join):

var split = "my name is kevin".match(/([^\s]+)/g), reversed = ""; while(split.length) reversed += split.pop() + " "; alert(reversed);

Open in new window

0
 
stargateatlantisAuthor Commented:
sorry I know I was looking for a for loop solution
0
 
basicinstinctCommented:
why loop in javascript when you can loop in native code?

is this homework?
0
 
stargateatlantisAuthor Commented:
Its homework.  Wouldn't it be faster to use a loop?
0
 
basicinstinctCommented:
nope
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.