Write JavaScript statements to accomplish each of the following tasks:
a) Display the value of the seventh element of array f.
b) Initialize each of the five elements of one-dimensional array g to 8.
c) Total the elements of array c, which contains 100 numeric elements.
d) Copy 11-element array a into the first portion of array b, which contains 34 elements.
e) Determine and print the smallest and largest values contained in 99-element floatingpoint array w
HTML java script in one code for all
Answers:
A: document.writeln( f[ 6 ] ); (To display the value of the seventh element of array f)
B: for ( var x = 0; x < 5; x++ ){
g[ x ] = 8;
} (Initialize each of the five elements of one-dimensional array g to 8)
C:
var total = 0;
for ( var x in c ){
total += c[ x ];
} (Total the elements of array c, which contains 100 numeric elements)
D:
for ( var x in a ){
b[ x ] = a[ x ];
} (Copy 11-element array a into the first portion of array b, which contains 34 elements)
E:
function sortNumber( x, y ){
return x - y;
}
w.sort( sortNumber );
document.write( "Smallest value: " + w[ 0 ] + "<br />"
);
document.write( "Largest value: " + w[ 98 ] + "<br />"
);
(Determine and print the smallest and largest values contained in 99-element floating-point array w)
Get Answers For Free
Most questions answered within 1 hours.