Skip to main content
added 795 characters in body
Source Link

There is good advice in the answer by adrianton3. I noticed one other thing:

You may have already updated the structure of the board based on adrianton3's answer but instead of this:

let gameboard = []; // = ["*", "*", "*", "*", "*", "*", "*", "*", "*"];
let symbol = "*";
for (let i = 0; i < 9; i++) {
  gameboard[i] = symbol;
}

it could be simplified to use Array.fill():

const symbol = "*";
const gameboard = Array(9).fill(symbol);

That way there is no need to loop through the board when initializing the default values.


It likely won't be an issue when users input numbers 0-9 but something to be aware of is that calls to parseInt() without a radix parameter may yield unexpected results if the input happens to contain a leading zero (or else hex prefix: 0x).

If the radix is undefined, 0, or unspecified, JavaScript assumes the following:

  1. If the input string begins with "0x" or "0X" (a zero followed by lowercase or uppercase X), radix is assumed to be 16 and the rest of the string is parsed as a hexidecimal number. 2. If the input string begins with "0" (a zero), radix is assumed to be 8 (octal) or 10 (decimal). Exactly which radix is chosen is implementation-dependent. ECMAScript 5 clarifies that 10 (decimal) should be used, but not all browsers support this yet. For this reason always specify a radix when using parseInt. 3. If the input string begins with any other value, the radix is 10 (decimal).1

See this post for more information.

1https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt#Description

There is good advice in the answer by adrianton3. I noticed one other thing:

You may have already updated the structure of the board based on adrianton3's answer but instead of this:

let gameboard = []; // = ["*", "*", "*", "*", "*", "*", "*", "*", "*"];
let symbol = "*";
for (let i = 0; i < 9; i++) {
  gameboard[i] = symbol;
}

it could be simplified to use Array.fill():

const symbol = "*";
const gameboard = Array(9).fill(symbol);

That way there is no need to loop through the board when initializing the default values.


It likely won't be an issue when users input numbers 0-9 but something to be aware of is that calls to parseInt() without a radix parameter may yield unexpected results if the input happens to contain a leading zero (or else hex prefix: 0x). See this post for more information.

There is good advice in the answer by adrianton3. I noticed one other thing:

You may have already updated the structure of the board based on adrianton3's answer but instead of this:

let gameboard = []; // = ["*", "*", "*", "*", "*", "*", "*", "*", "*"];
let symbol = "*";
for (let i = 0; i < 9; i++) {
  gameboard[i] = symbol;
}

it could be simplified to use Array.fill():

const symbol = "*";
const gameboard = Array(9).fill(symbol);

That way there is no need to loop through the board when initializing the default values.


It likely won't be an issue when users input numbers 0-9 but something to be aware of is that calls to parseInt() without a radix parameter may yield unexpected results if the input happens to contain a leading zero (or else hex prefix: 0x).

If the radix is undefined, 0, or unspecified, JavaScript assumes the following:

  1. If the input string begins with "0x" or "0X" (a zero followed by lowercase or uppercase X), radix is assumed to be 16 and the rest of the string is parsed as a hexidecimal number. 2. If the input string begins with "0" (a zero), radix is assumed to be 8 (octal) or 10 (decimal). Exactly which radix is chosen is implementation-dependent. ECMAScript 5 clarifies that 10 (decimal) should be used, but not all browsers support this yet. For this reason always specify a radix when using parseInt. 3. If the input string begins with any other value, the radix is 10 (decimal).1

See this post for more information.

1https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt#Description

added 352 characters in body
Source Link

There is good advice in the answer by adrianton3. I noticed one other thing:

You may have already updated the structure of the board based on adrianton3's answer but instead of this:

let gameboard = []; // = ["*", "*", "*", "*", "*", "*", "*", "*", "*"];
let symbol = "*";
for (let i = 0; i < 9; i++) {
  gameboard[i] = symbol;
}

it could be simplified to use Array.fill():

const symbol = "*";
const gameboard = Array(9).fill(symbol);

That way there is no need to loop through the board when initializing the default values.


It likely won't be an issue when users input numbers 0-9 but something to be aware of is that calls to parseInt() without a radix parameter may yield unexpected results if the input happens to contain a leading zero (or else hex prefix: 0x). See this post for more information.

There is good advice in the answer by adrianton3. I noticed one other thing:

You may have already updated the structure of the board based on adrianton3's answer but instead of this:

let gameboard = []; // = ["*", "*", "*", "*", "*", "*", "*", "*", "*"];
let symbol = "*";
for (let i = 0; i < 9; i++) {
  gameboard[i] = symbol;
}

it could be simplified to use Array.fill():

const symbol = "*";
const gameboard = Array(9).fill(symbol);

That way there is no need to loop through the board when initializing the default values.

There is good advice in the answer by adrianton3. I noticed one other thing:

You may have already updated the structure of the board based on adrianton3's answer but instead of this:

let gameboard = []; // = ["*", "*", "*", "*", "*", "*", "*", "*", "*"];
let symbol = "*";
for (let i = 0; i < 9; i++) {
  gameboard[i] = symbol;
}

it could be simplified to use Array.fill():

const symbol = "*";
const gameboard = Array(9).fill(symbol);

That way there is no need to loop through the board when initializing the default values.


It likely won't be an issue when users input numbers 0-9 but something to be aware of is that calls to parseInt() without a radix parameter may yield unexpected results if the input happens to contain a leading zero (or else hex prefix: 0x). See this post for more information.

Source Link

There is good advice in the answer by adrianton3. I noticed one other thing:

You may have already updated the structure of the board based on adrianton3's answer but instead of this:

let gameboard = []; // = ["*", "*", "*", "*", "*", "*", "*", "*", "*"];
let symbol = "*";
for (let i = 0; i < 9; i++) {
  gameboard[i] = symbol;
}

it could be simplified to use Array.fill():

const symbol = "*";
const gameboard = Array(9).fill(symbol);

That way there is no need to loop through the board when initializing the default values.