nerdexam
Microsoft

98-382 · Question #16

Your instructor has asked you to implement code that would display a two-dimensional array of any size inside a <div> tag. You write the following code: ``javascript var div =…

The correct sequence of code segments to display the two-dimensional array is: ``javascript for (var i = 0; i < board.length; i++) { for (var j = 0; j < board[0].length; j++) { div.innerHTML = div.innerHTML + board[i][j] + ' '; } div.innerHTML = div.innerHTML + '<br>'; } ``

Working with the Document Object Model (DOM)

Question

Your instructor has asked you to implement code that would display a two-dimensional array of any size inside a <div> tag. You write the following code:
var div = document.getElementById('board');
var board = [['-','X','-','X'], ['-','O','X','O'], ['X','O','-','O']];
You need to complete the code. Which three segments should you use to develop the solution? To answer, move the appropriate code segments from the list of code segments to the answer area and arrange them in the correct order.

Explanation

The correct sequence of code segments to display the two-dimensional array is:

for (var i = 0; i < board.length; i++) {
    for (var j = 0; j < board[0].length; j++) {
        div.innerHTML = div.innerHTML + board[i][j] + ' ';
    }
    div.innerHTML = div.innerHTML + '<br>';
}

Topics

#2D arrays#nested loops#DOM manipulation#innerHTML

Community Discussion

No community discussion yet for this question.

Full 98-382 Practice