diff --git a/01_Acey_Ducey/javascript/aceyducey.js b/01_Acey_Ducey/javascript/aceyducey.js index 61525a3d..8bf5e9e1 100644 --- a/01_Acey_Ducey/javascript/aceyducey.js +++ b/01_Acey_Ducey/javascript/aceyducey.js @@ -27,14 +27,14 @@ function getRandomCard() { return Math.floor(Math.random() * (max - min + 1) + min); } -function getGameCards() { +function newGameCards() { let cardOne = getRandomCard(); let cardTwo = getRandomCard(); let cardThree = getRandomCard(); // We want: // 1. cardOne and cardTwo to be different cards // 2. cardOne to be lower than cardTwo - // So, while cardOne is greater than or equal two cardTwo + // So, while cardOne is greater than or equal too cardTwo // we will continue to generate random cards. while (cardOne >= cardTwo) { cardOne = getRandomCard(); @@ -75,7 +75,7 @@ async function main() { // Loop game forever while (true) { - let [cardOne, cardTwo, cardThree] = getGameCards(); + let [cardOne, cardTwo, cardThree] = newGameCards(); print(`YOU NOW HAVE ${availableDollars} DOLLARS.\n`); diff --git a/01_Acey_Ducey/javascript/util.js b/01_Acey_Ducey/javascript/util.js deleted file mode 100644 index 418eff40..00000000 --- a/01_Acey_Ducey/javascript/util.js +++ /dev/null @@ -1,67 +0,0 @@ -// By default: -// — Browsers have a window object -// — Node.js does not -// Checking for an undefined window object is a loose check -// to enable browser and Node.js support -const isRunningInBrowser = typeof window !== 'undefined'; - -const outputElement = document.querySelector('#output'); - -function print(string) { - if (isRunningInBrowser) { - // Adds trailing newline to match console.log behavior - document - .getElementById('output') - .appendChild(document.createTextNode(string + '\n')); - } else { - console.log(string); - } -} - -function input() { - if (isRunningInBrowser) { - // Accept input from the browser DOM input - return new Promise((resolve) => { - const inputEl = document.createElement('input'); - outputElement.append(inputEl); - inputEl.focus(); - - inputEl.addEventListener('keydown', (event) => { - if (event.key === 'Enter') { - const result = inputEl.value; - inputEl.remove(); - print(result); - print(''); - resolve(result); - } - }); - }); - } else { - // Accept input from the command line in Node.js - // See: https://nodejs.dev/learn/accept-input-from-the-command-line-in-nodejs - return new Promise(function (resolve) { - const readline = require('readline').createInterface({ - input: process.stdin, - output: process.stdout, - }); - readline.question('', function (input) { - resolve(input); - readline.close(); - }); - }); - } -} - -function printInline(string) { - if (isRunningInBrowser) { - document - .getElementById('output') - .appendChild(document.createTextNode(string)); - } else { - process.stdout.write(string); - } -} - -function spaces(numberOfSpaces) { - return ' '.repeat(numberOfSpaces); -}