Answers for "creating a nested loop of a chessboard in javascript"

0

creating a nested loop of a chessboard in javascript

function chessboard() {

    let columns = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'];
    let rows = [1, 2, 3, 4, 5, 6, 7, 8];

    const chessboard = [];
    
    for(let i = 0; i<columns.length; i++){
        let currentRow = [];
        // console.log (columns[i])
            for (let j = 0; j < rows.length; j++){
            // console.log(rows[j]);
            currentRow.push(`${columns[i]} - ${rows[j]}`)
        } 
    
        // console.log(currentRow) 
        // return position
        chessboard.push(currentRow)
    } 
    console.log(chessboard)

    return chessboard;
}
module.exports = chessboard;
Posted by: Guest on October-20-2020

Code answers related to "creating a nested loop of a chessboard in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language