Computer Science, asked by siddharthtiwary037, 1 month ago

Predict the output!
var arr = newArray (20,5,6,3,9);
for (I=0;I<5;I++)
{if(arr[i]%2==0)
document.write (arr[i]);
}​

Attachments:

Answers

Answered by anindyaadhikari13
4

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.

Similar questions