Chessboard: findColor
unknown
javascript
3 years ago
670 B
11
Indexable
/**
*
* @param {boolean} startingColor true: black false: white
* @param {number} x positive number
* @param {number} y positive number
* @returns true if the coordinates of (x,y) cell equal to first cell (1,1) color
*/
const findColor = (startingColor, x, y) => {
cell1 = 1 + 1;
cell2 = x + y;
if (!Number.isInteger(x) || !Number.isInteger(y))
return 'please enter a valid values.'
return startingColor ? cell1 % 2 === cell2 % 2 : !(cell1 % 2 === cell2 % 2)
}
console.log(findColor(false, 1, 2)) // true
console.log(findColor(true, 1, 2)) // false
console.log(findColor(false, 2 , 2)) // false
console.log(findColor(true, 2, 2)) // trueEditor is loading...