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.
initialise precedingCharacter to an empty string
for each position in the string
assign the character at that position to currentCharacter
if (isVowel(currentCharacter) AND (NOT isVowel(precedingCharacter))
concatenate 'ub' to the result string
concatenate currentCharacter to the result string
assign the current character to precedingCharacter
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 .
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.
// variable to hold resultString
var resultString = '';
// variable to hold the current and previous characters
// 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'
if (result1 == 'thube cubat subat ubon thube mubat')
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!