Could somebody please take a look at the lines of coding below and advise on how to complete it? It's a code to translate a piece of text, I kinda figured some of it out, but could use some help!
The first part is to translate 'the cat sat on the mat' to 'thube cubat subat ubon thube mubat'.
The second part is entering text and clicking a button to translate.
function ubbiDubbi(aString)
{
// variable to hold resultString
var resultString = '';
// variable to hold the current and previous characters
var currentCharacter;
var precedingCharacter;
// in the case of the first character in the string there is no
// previous character, so we assign an empty string '' to the variable at first
precedingCharacter = '';
// TEST
var string1 = 'the cat sat on the mat';
var result1 = ubbiDubbi(string1); // result should be 'thube cubat subat ubon thube mubat'
document.write(string1)
document.write('<BR>');
document.write(result1)
document.write('<BR>');
if (result1 == 'thube cubat subat ubon thube mubat')
{
document.write('test passed');
}
document.write('<BR>');
Second Part has the below HTML codes available, but requires the following structured english to be converted into code:
access the value of the textbox original
if the value equals the empty string
issue a warning in an alert box
else
set the value of the translation textbox to be the original value translated into Ubbi Dubbi
end if
<FORM NAME = "translator">
Please enter a phrase
<BR>
<INPUT TYPE = "text"
NAME = "original"
SIZE = "40"
VALUE = ''>
<BR>
<INPUT TYPE = "button"
VALUE = "Translate into Ubbi Dubbi"
ONCLICK = "translateIntoUbbiDubbi();">
<BR>
Translation into Ubbi Dubbi is
<BR>
<INPUT TYPE = "text"
NAME = "translation"
SIZE = "40"
VALUE = ''>
I am not to sure what you mean by that, but I'll try and explain what I expect from the coding a bit better.
For the first bit I want a line of coding that translates and outputs pieces of text from variables into Ubbi Dubbi. The code is supposed to identify vowels, using loops, and inserting 'ub' in front of the vowels. Then 2 variables are set to test the code. First 'string1' - the cat is on the mat, second 'result1' - the cat is on the mat translated into Ubbi Dubbi (so; thube cubat subat ubon thube mubat)
The second bit of coding is a bit like the first, but includes HTML and has a skeleton function. The skeleton function is to call on var result1 = ubbiDubbi. The FORM "translator" is supposed to output text entered into the input text box, a translate button then translates the inserted text into Ubbi Dubbi. When there is no text entered a window.alert is prompted. The code in written English would be:
access the value of the textbox original
if the value equals the empty string
issue a warning in an alert box
else
set the value of the translation textbox to be the original value translated into Ubbi Dubbi
end if
I am not to sure what you mean by that, but I'll try and explain what I expect from the coding a bit better.
...
I hope that makes a bit more sense?
Not really ... It appears that 'ub' goes in front of the 1st vowel
Is this the only rule as you have given words with only one vowel?
By rules I mean: What happens to words with more than one vowel?
Words like:
receive ... should it be 'rubceive' or 'rubcubeubiveub'?
meat ... should it be 'mubeat' or 'mubeubat'?
Thanks for the code.
i'm trying to put it to work with a NAME instead of ID in the form. Can you please help?
Also, how can I add a validation in the form to pop-up an alert if no string is inserted into the form?
Thanks
I don't understand why you would need a <form>?
You should:
1. Show the code you are using
and
2. Start your own thread as this OP feels the problem is resolved.
Often times other forum members will not feel like looking at resolved problems.
Please enter a phrase
<BR>
<INPUT TYPE = "text"
ID = "original"
SIZE = "40"
VALUE = ''>
<BR>
<!-- the ONCLICK attribute is assigned the function translateIntoUbbiDubbi()-->
<INPUT TYPE = "button"
VALUE = "Translate into Ubbi Dubbi"
ONCLICK = "translateIntoUbbiDubbi();">
<BR>
Translation into Ubbi Dubbi is
<BR>
<INPUT TYPE = "text"
ID = "translation"
SIZE = "40"
VALUE = ''>
Please enter a phrase
<BR>
<INPUT TYPE = "text"
NAME = "original"
SIZE = "40"
VALUE = ''>
<BR>
<!-- the ONCLICK attribute is assigned the function translateIntoUbbiDubbi()-->
<INPUT TYPE = "button"
VALUE = "Translate into Ubbi Dubbi"
ONCLICK = "translateIntoUbbiDubbi();">
<BR>
Translation into Ubbi Dubbi is
<BR>
<INPUT TYPE = "text"
NAME = "translation"
SIZE = "40"
VALUE = ''>
Thanks if I replace your function toUbbiDubbi(wrd) with the provided one
function ubbiDubbi(aString)
{
// variable to hold resultString
var resultString = '';
// variable to hold the current and previous characters
var currentCharacter;
var precedingCharacter;
// in the case of the first character in the string there is no
// previous character, so we assign an empty string '' to the variable at first
precedingCharacter = '';
Bookmarks