1.

Predict the output!var arr = newArray (20,5,6,3,9);for (I=0;I

Answer»

Corrected Co‎de:

Language: JavaScript.

var arr = new Array(20,5,6,3,9);

for (i=0;i<5;i++){

if(arr[i]%2==0)

document.write(arr[i]);

}

Output:

  • The output of this co‎‎‎de is – 206.

Explanation:

  • Line 1: An array of 5 variables is declared.
  • Line 2: A for LOOP USED to transverse through array elements.
  • Line 3: Check if the array ELEMENT is DIVISIBLE by 2 or not.
  • Line 4: If true, the array element is displayed.

The given co‎de PRINTS the even elements of the array.

20 and 6 are the even elements in the array.

So, output – 206.



Discussion

No Comment Found