Need A Lot of Assistance From An Actual js Dev

OK thanks I got it.

This was my final solution. It’s not perfect but, it works.


// Declare all variables.

      /*
      declare size variable.
      do prompt toward user for size number over and over while user enters anything but a number.
      Something is broken here and I don't know what. It works the first time, after that it just enters an empty string.
      Can't figure out why.
      */
      let size;
      do {
        size = prompt("Please enter a number.");
      } while (size == NaN);
          size = prompt("Please enter a number.");



      let chess_grid_white = " ";
      let chess_grid_black = "#";
      let chess_grid_newline = "\n";
      let chess_grid_row_odd = "";
      let chess_grid_row_even = "";
      let chess_grid_final_output = "";
      let loop_index = 0;

      // Using a while loop for odd row generation.
      /* while loop index is less than size generate rows based on if branch.
      if loop index is divisible by 2 with no remainder, generate a white space.
      else generate a black space.
      concatnate and update odd row.
      move to the next loop index.*/
      while (loop_index < size) {
        if (loop_index % 2 == 0)
          chess_grid_row_odd = chess_grid_row_odd + chess_grid_white;
        else
          chess_grid_row_odd = chess_grid_row_odd + chess_grid_black;
        loop_index = loop_index + 1;
      }


      // Using a while loop for even row generation.
      /* 
      reset loop index variable.
      while loop index is less than size generate rows based on if branch.
      if loop index is divisible by 2 with no remainder, generate a black space.
      else generate a white space.
      concatnate and update even row variable.
      move to the next loop index.*/

      loop_index = 0; 
      while (loop_index < size) {
        if (loop_index % 2 == 0)
          chess_grid_row_even = chess_grid_row_even + chess_grid_black;
        else
          chess_grid_row_even = chess_grid_row_even + chess_grid_white;
        loop_index = loop_index + 1;
      };


      // Using a while loop for final output generation.
      /* 
      reset loop index variable.
      while loop index is less than size generate output.
      concatnate and update final output variable.
      move to the next loop index.*/

                                  
      loop_index = 0;                                                           
      while (loop_index < size) {
        chess_grid_final_output = chess_grid_final_output + chess_grid_row_odd + chess_grid_newline;
        chess_grid_final_output = chess_grid_final_output + chess_grid_row_even + chess_grid_newline;            
        loop_index = loop_index + 1;
      }


      //Resetting variable values.
      loop_index = 0;
      chess_grid_row_even = "";
      chess_grid_row_odd = "";
      
      // output in console.
      console.log(chess_grid_final_output);

      console.log(" ");
      console.log("This ends the exercise!");
      console.log(" ");

What do you think?

2 Likes