This commit is contained in:
LukasMurdock
2022-01-01 20:45:19 -05:00
parent c2dc4c8b38
commit 5c994e9562
2 changed files with 3 additions and 70 deletions

View File

@@ -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`);

View File

@@ -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);
}