Question
/*Hello, I really hope someone can help me out with this function. I'm a newbie to JavaScript. I have included the instructions for the swapFE() function that I have to complete below along with the functions that I have done so far.
I need to create a swap function. The purpose of this function is to exchange the French phrase for the English translation. The function has a single parameter, the event object e.
a. store the source of the event in a variable named phrase. This variable represents the phrase that was clicked in the document. I need to create a cross-browser function or insert code that will determine the source of the event.
b. There are 10 phrases in the document. Determine the phrase number by extracting the integer value from the previous sibling of the phrase node. I have to use the parseInt() function to apply it to the inner content of the previous sibling node. Store the phrase number in the variable phrasenum.
c. The index values from the English and French arrays range from 0 to 9. Change the inner content of the phrase node to the value of the array item english[phrasenum -1] where phrasenum is the value of the phrasenum variable.
d. Change the font style of the phrase node to normal. Change the color of the phrase node to the color value(155, 102,102).
*/
function eventSource(e) {
var IE = document.attachEvent ? true:false;
Var DOM = document.addEventListener ? true:false;
if (IE) return event.srcElement;
else
if (DOM) return e.currentTarget;
}
function SetUpTranslation () {
var phrases = document.getElementsByTagName('p');
for (var i=0; i<p.attributes.length;i++){
phrases.secondNode.innerHTML=french[i];
element.onclick=swapFE(phrase.childNode[1]);
element.onmousedown=swapFE(phrases.childNode[1]);
}
}
/*This is the function I need help with*/
function swapFe(e) {
var phrase = eventSource(e);
var phrasenum = parseInt(phrase.previousSibling.innerHTML = english[phrasenum -1].value);
}
/* Thanks for your assistance.*/
I need to create a swap function. The purpose of this function is to exchange the French phrase for the English translation. The function has a single parameter, the event object e.
a. store the source of the event in a variable named phrase. This variable represents the phrase that was clicked in the document. I need to create a cross-browser function or insert code that will determine the source of the event.
b. There are 10 phrases in the document. Determine the phrase number by extracting the integer value from the previous sibling of the phrase node. I have to use the parseInt() function to apply it to the inner content of the previous sibling node. Store the phrase number in the variable phrasenum.
c. The index values from the English and French arrays range from 0 to 9. Change the inner content of the phrase node to the value of the array item english[phrasenum -1] where phrasenum is the value of the phrasenum variable.
d. Change the font style of the phrase node to normal. Change the color of the phrase node to the color value(155, 102,102).
*/
function eventSource(e) {
var IE = document.attachEvent ? true:false;
Var DOM = document.addEventListener ? true:false;
if (IE) return event.srcElement;
else
if (DOM) return e.currentTarget;
}
function SetUpTranslation () {
var phrases = document.getElementsByTagName('p');
for (var i=0; i<p.attributes.length;i++){
phrases.secondNode.innerHTML=french[i];
element.onclick=swapFE(phrase.childNode[1]);
element.onmousedown=swapFE(phrases.childNode[1]);
}
}
/*This is the function I need help with*/
function swapFe(e) {
var phrase = eventSource(e);
var phrasenum = parseInt(phrase.previousSibling.innerHTML = english[phrasenum -1].value);
}
/* Thanks for your assistance.*/