3.
Given a function specialSum(x,y,z) that:
a. Returns the sum of (x, the absolute value of y, z) e.g. x+|y|+z
b. All parameters are optional
c. Always returns an integer.
What values of x, y, z, and return value are necessary to verify that this
function performs as specified in PHP? To start you out
specialSum(2+2+2)=>6 and specialSum()=>0 are two of the tests I’m looking
for. Are there any differences in Javascript?
5. Identify potential problems and inefficiencies with the following
Javascript, explain each problem and how you would fix it. Not all
problems are syntactic.
<script type="text/javascript">
function newObject(objectName) {
ex = "ret = new " + objectName + "();";
eval(ex);
return ret;
}
startUp = newObject('PSUtil');
if ( startUp.message != undefined ) {
document.getElementById('startMessage').value = startup.message;
}
startUp.engine = newObject(startUp.workingClass);
startUp.specialElements = givenSelectionFunction();
function wireFunction(elements ) {
for ( i=0; i < elements.length ; i ++ ) {
el = document.getElementById(elements);
for ( i=0; i < startUp.specialElements.elements.ids.length ; i++ )
{
if ( elements == startUp.specialElements.elements.ids ) {
el.onchange = startUp.specialElements.specialFunction;
}
}
for ( f in funcs ) {
el.attachEvent(f,funcs[f]);
}
}
};
wireFunctions ( startUp.engine.veryLargeArrayOfElementIDs);
function givenSelectionFunction() {
var elementArray = new Array();
working = document.getElementsByTagName('special');
for ( i=0; i<working.length; i++ ) {
var myTestFunction = function(el) {
if ( /* some complex test of el that must be in a function */) {
return true;
} else {
return false;
}
};
if (myTestFunction([working) ) {
elementArray.push(working);
}
}
return