IGNORE QUESTION 4 3 15 marks Consider the following code fra
IGNORE QUESTION 4
3. 15 marks] Consider the following code fragments for index3.htmlSolution
Please note that the attribute name like \"2nd\" not allowed in javascript as it is giving error I used attribute name as \"second\"
function is as follows:
function myfunc(a,b,c)
{
var test = new Object();
// document.write(a);
var temparr = new Array();
for (var i=0;i<a.length;i++ )
{
temparr.push(a[i]*a[i]);
// document.write(a[i]*a[i]);
}
test.first = temparr;
// document.write(b.length);
var strtemp =new String(b);
for (var i=0;i<b.length;i++ )
{
if(b[i]>=0 && b[i]<=9)
{
}
else
{
// document.write(\"b[i]:\"+b[i]+\" i:\"+i+\" str:\"+strtemp[i]);
strtemp = strtemp.replace(b[i],\'\');
}
}
//document.write(strtemp);
test.second = strtemp;
var firstChar=c[0];
// var str=new String(c);
// document.write(firstChar);
var s1=new String(firstChar);
var s2=new String(firstChar);
var s3=new String(firstChar);
var s4=new String(firstChar);
var s5=new String(firstChar);
var s6=new String(c.substr(1,(c.length-1)));
var fstr = new String();
fstr = s1.concat(s2,s3,s4,s5,s6);
// document.write(fstr);
test.three=fstr;
return test;
}
I/P:
var retOb=myfunc([1,2,3,4],\"abc123def456\",\"hello\");
document.write(retOb.first);
O/p:
1,4,9,16
any more explanations andcorrections required please post a comment.
![IGNORE QUESTION 4 3. 15 marks] Consider the following code fragments for index3.html SolutionPlease note that the attribute name like \ IGNORE QUESTION 4 3. 15 marks] Consider the following code fragments for index3.html SolutionPlease note that the attribute name like \](/WebImages/32/ignore-question-4-3-15-marks-consider-the-following-code-fra-1093981-1761576503-0.webp)
![IGNORE QUESTION 4 3. 15 marks] Consider the following code fragments for index3.html SolutionPlease note that the attribute name like \ IGNORE QUESTION 4 3. 15 marks] Consider the following code fragments for index3.html SolutionPlease note that the attribute name like \](/WebImages/32/ignore-question-4-3-15-marks-consider-the-following-code-fra-1093981-1761576503-1.webp)