Get Sudoku Puzzle and Create the Board

Introduction

We completed all the setup for displaying the Sudoku board in the previous lesson. Now, we are going to fetch the Sudoku puzzle that will give us a 2D matrix pre-filled with some numbers. We also need to display the puzzle in the form of a Sudoku board on the HTML web page. When the user clicks on the "Get New Puzzle" button on the UI, the application should fetch a new puzzle and display it on the UI. We'll perform the following steps in this lesson:

  1. Fetch the Sudoku puzzle using the API that has already been set up in the code widget.

  2. Set the flag for the filled cells in the Sudoku board to true.

  3. Display the Sudoku puzzle received from the API on a button click event.

Fetch the Sudoku puzzle from the API

We need to create a function to call the API and get the Sudoku question. We will be using the XMLHttpRequest object to create a GET request to get the response from the API, and we'll be calling the below API to get the Sudoku puzzle:

Get hands-on with 1200+ tech skills courses.