62 541
Assignments Done
98,7%
Successfully Done
In June 2018

Answer to Question #3245 in AJAX | JavaScript | HTML | PHP for lee

Question #3245
Can someone advice me with this javascript please...?
Hi all could someone help me out with this please.

You will have seen that the outline code also contains a partially written function ubbiDubbi() which is to take a string argument and translate it into Ubbi Dubbi according to the rule we are using.
Currently this function declares and initialises some variables but contains no code that will actually translate the argument. The structured English below describes the algorithm necessary to perform the translation. For convenience we have numbered the steps.
1.
initialise precedingCharacter to an empty string
2.
for each position in the string
3.
assign the character at that position to currentCharacter
4.
if (isVowel(currentCharacter) AND (NOT isVowel(precedingCharacter))
5.
concatenate 'ub' to the result string
6.
end if
7.
concatenate currentCharacter to the result string
8.
assign the current character to precedingCharacter
9.
end for
10.
return the result string


Does anyone know what code goes in the script below from the stuctured english above thanks





// Program to translate a message into "Ubbi Dubbi"


// PROVIDED FUNCTION -- you do not need to change it

/*
* determines if the argument is a vowel
*
* function takes one argument representing a character to be tested and returns
* -- true if the argument is a single uppercase or lowercase character which is a vowel
* -- false otherwise .
*/
function isVowel(aCharacter)
{
return ((aCharacter == 'a') || (aCharacter == 'A')||
(aCharacter == 'e') || (aCharacter == 'E')||
(aCharacter == 'i') || (aCharacter == 'I')||
(aCharacter == 'o') || (aCharacter == 'O')||
(aCharacter == 'u') || (aCharacter == 'U')||
(aCharacter == 'y') || (aCharacter == 'Y'));
}


// INCOMPLETE FUNCTION -- supply missing code where indicated for part (ii)(a)

/*
* translates a word into Ubbi Dubbi
*
* function takes a string argument and returns a second string
* which is the first one translated into Ubbi Dubbi.
*/
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 = '';

// TODO part (ii)
// add code as directed in the question
}

// TEST 1
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>');
Expert's answer
Unfortunately, your question requires a lot of work and cannot be done for free. Submit it with all requirements as an assignment to our control panel and we&#039;ll assist you.

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions