0

I am making an application using jQuery. In my app, the user enters some input like:
"We are going to party"
and when he clicks on the convert button, the result should be:
"V R GNG 2 PRTY".

But in my code, I am getting only last value as a result.

The code is at pastebin.com/NWMavENb.
I want the result to be "V R GNG 2 PRTY".Here is my page you can download http://www.mediafire.com/?cj5lz68di25dzx22 this page.

0

2 Answers 2

1

For each of your conditional if tests (and yes there are many ways to do this), try

if(words[i].toLowerCase() == "going") // case-insensitive test
{
    words[i] = "GNG";
}

and then after the end of your loop, reassign the value to your destination element.

$("#cnvalue").val(words.join(' '));
Sign up to request clarification or add additional context in comments.

Comments

0

You are simply changing the value every time, so only the last value is stored. You need to keep track of the value and append to it.

Here is one way

if(words[i]=="Are"||words[i]=="are"||words[i]=="ARE")
{
    $("#cnvalue").val($("#cnvalue").val() + " R");
}

3 Comments

You forgot 'aRe' and 'arE' ;) Please you toLowerCase or toUpperCase for this.
Good suggestion... but you should suggest it to @Sandeep.
Dear sir, mediafire.com/?cj5lz68di25dzx2 please check my post and suggest me what i am doing wrong with my code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.