Last active
June 18, 2023 18:44
-
-
Save axiand/2a233b59819526f6f23eadfde0255416 to your computer and use it in GitHub Desktop.
snailrace.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
//ex. SnailRace("red") | |
var SnailRace = function (bet) { | |
let snails = {'red': 0, 'blue': 0, 'green': 0, 'yellow': 0};if(!Object.keys(snails).includes(bet)) {return this.SnailRaceResult = `Invalid input; must be one of: ${Object.keys(snails).join(", ")}`}; let winState = false;let winner = null;while(!winState) {for(let snail in snails) {snails[snail] += Math.round(Math.random()*3); if(snails[snail] >= 25) {winState = true; winner = snail}}}let print = '';for(let snail in snails) {print += `${winner==snail?'๐':''}๐ ${snail} ${snails[snail]}cm\n`;}print += `${winner} crossed the finish line first!! You bet for ${bet}. Was your bet correct? ${winner==bet&&'Yes!'}`; return print | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment