Created
March 2, 2019 01:01
-
-
Save webercoder/43f7530ec67f375a1fe86da06ec257cd to your computer and use it in GitHub Desktop.
make-number-puzzle.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getRandomInt(max) { | |
return Math.floor(Math.random() * Math.floor(max)); | |
} | |
function makePuzzle(rows = 5, columns = 5, max = 20) { | |
const find = getRandomInt(max); | |
console.log(`Find the number ${find}`); | |
const puzzle = []; | |
for (let i = 0; i < rows; i++) { | |
puzzle[i] = []; | |
const findColumn = getRandomInt(columns); | |
for (let j = 0; j < columns; j++) { | |
if (j === findColumn - 1) { | |
puzzle[i].push(find); | |
} else { | |
puzzle[i].push(getRandomInt(max)); | |
} | |
} | |
} | |
puzzle.forEach(row => console.log(row.join('\t'))); | |
console.log(' '); | |
} | |
for (let i = 0; i < 7; i++) { | |
makePuzzle(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment