Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Oct 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    reverse the order of words

    So far I have this program reversing the letters in a sentence. What I need is for the user to be able to enter one word at a time to make a sentence while the program reverses the order of the words and displays them. If someone could please tell me what I am doing wrong. Thank You

    html

    Code:
    <!doctype html>
    <html>
    	<head>
    		<title>Sentence Reverser</title>
    		<meta charset="utf-8" />
    		<script type="text/javascript" src="hunt.js"></script>
    	</head>
    	<body>
    		<form name="reverseForm" action="#">
    		
    			<label for="output">Reversed Sentence</label><br />
    			<textarea name="output" row="3" cols="24"></textarea>
    			
    			<input type="button" value="Run!" onclick="do_work()" />
    		</form>
    	</body>
    </html>

    JS

    Code:
    <!doctype html>
    <html>
    	<head>
    		<title>Sentence Reverser</title>
    		<meta charset="utf-8" />
    		<script type="text/javascript" src="hunt.js"></script>
    	</head>
    	<body>
    		<form name="reverseForm" action="#">
    		
    			<label for="output">Reversed Sentence</label><br />
    			<textarea name="output" row="3" cols="24"></textarea>
    			
    			<input type="button" value="Run!" onclick="do_work()" />
    		</form>
    	</body>
    </html>

  • #2
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,071
    Thanks
    38
    Thanked 498 Times in 492 Posts
    Is this some sort of class assignment?
    See: sentence reverser

  • #3
    New to the CF scene
    Join Date
    Oct 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yes it is but when you referred me to the link with plat, that is my mother. we are going to school together and have the same class. But if you don't want to help then don't. Thanks for helping my mother.

  • #4
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,910
    Thanks
    15
    Thanked 227 Times in 227 Posts
    Presumably the words in a text string will be separated by spaces, so you just use .split(" ") to change the string into an array of words. You just reassemble the words into another string with the words in reverse order, adding spaces. You just use a for loop but run 'backwards', to do the job.
    Welcome to http://www.myphotowizard.net

    where you can edit images, make a photo calendar, add text to images, and do much more.


    When you know what you're doing it's called Engineering, when you don't know, it's called Research and Development. And you can always charge more for Research and Development.

  • #5
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    You say you have already written some JavaScript code, but you jsut linked your HTML twice, with no code......

  • #6
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    A little message from the OP. She is apparenly upset that i pointed out that it appears that she hasn't written any JS code at all and is hoping we will jsut do it for her, which someone jsut has lol.


    Code:
    This is Britani and if you were talking to me about the code well I am new to this that's why
     I am in class. I don't understand some of you people. Didn't your momma ever tell you that if you
     don't have anything nice to say well keep your mouth shut. I posted on here because I just could 
    not figure out how to switch the words around. I thought the forum was for helping others who are
     not as good as you. If I was to ever get as good as you guys are I would feel very blessed. It is not 
    like I send in nothing and ask you all to do it for me. I do try to figure it out first. Anyway I hope you 
    have a very blessed and amazing day however mine is off to a bad start because someone wanted to
     be rude to me.
    so she is in class, and this apparently is her homework, which we just handed her on a platter lol.

  • Users who have thanked DanInMa for this post:

    mrhoo (10-05-2013)

  • #7
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,071
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Question

    Quote Originally Posted by jmrker View Post
    Is this some sort of class assignment?
    See: sentence reverser
    Quote Originally Posted by britani View Post
    yes it is but when you referred me to the link with plat, that is my mother. we are going to school together and have the same class. But if you don't want to help then don't. Thanks for helping my mother.
    OK, but why do you ask for a solution when one was already suggested elsewhere?
    What was wrong with those answers?


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •