├── README.md ├── package-lock.json ├── package.json └── project.js /README.md: -------------------------------------------------------------------------------- 1 | # JavaScript-Slot-Machine 2 | 3 | # 💻 Launch Your Software Development Career Today! 4 | 5 | 🎓 **No degree? No problem!** My program equips you with everything you need to break into tech and land an entry-level software development role. 6 | 7 | 🚀 **Why Join?** 8 | - 💼 **$70k+ starting salary potential** 9 | - 🕐 **Self-paced:** Complete on your own time 10 | - 🤑 **Affordable:** Low risk compared to expensive bootcamps or degrees 11 | - 🎯 **45,000+ job openings** in the market 12 | 13 | 👉 **[Start your journey today!](https://techwithtim.net/dev)** 14 | No experience needed—just your determination. Future-proof your career and unlock six-figure potential like many of our students have! 15 | -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "javascript-project", 3 | "version": "1.0.0", 4 | "lockfileVersion": 2, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "javascript-project", 9 | "version": "1.0.0", 10 | "license": "ISC", 11 | "dependencies": { 12 | "prompt-sync": "^4.2.0" 13 | } 14 | }, 15 | "node_modules/ansi-regex": { 16 | "version": "4.1.1", 17 | "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.1.tgz", 18 | "integrity": "sha512-ILlv4k/3f6vfQ4OoP2AGvirOktlQ98ZEL1k9FaQjxa3L1abBgbuTDAdPOpvbGncC0BTVQrl+OM8xZGK6tWXt7g==", 19 | "engines": { 20 | "node": ">=6" 21 | } 22 | }, 23 | "node_modules/prompt-sync": { 24 | "version": "4.2.0", 25 | "resolved": "https://registry.npmjs.org/prompt-sync/-/prompt-sync-4.2.0.tgz", 26 | "integrity": "sha512-BuEzzc5zptP5LsgV5MZETjDaKSWfchl5U9Luiu8SKp7iZWD5tZalOxvNcZRwv+d2phNFr8xlbxmFNcRKfJOzJw==", 27 | "dependencies": { 28 | "strip-ansi": "^5.0.0" 29 | } 30 | }, 31 | "node_modules/strip-ansi": { 32 | "version": "5.2.0", 33 | "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", 34 | "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", 35 | "dependencies": { 36 | "ansi-regex": "^4.1.0" 37 | }, 38 | "engines": { 39 | "node": ">=6" 40 | } 41 | } 42 | }, 43 | "dependencies": { 44 | "ansi-regex": { 45 | "version": "4.1.1", 46 | "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.1.tgz", 47 | "integrity": "sha512-ILlv4k/3f6vfQ4OoP2AGvirOktlQ98ZEL1k9FaQjxa3L1abBgbuTDAdPOpvbGncC0BTVQrl+OM8xZGK6tWXt7g==" 48 | }, 49 | "prompt-sync": { 50 | "version": "4.2.0", 51 | "resolved": "https://registry.npmjs.org/prompt-sync/-/prompt-sync-4.2.0.tgz", 52 | "integrity": "sha512-BuEzzc5zptP5LsgV5MZETjDaKSWfchl5U9Luiu8SKp7iZWD5tZalOxvNcZRwv+d2phNFr8xlbxmFNcRKfJOzJw==", 53 | "requires": { 54 | "strip-ansi": "^5.0.0" 55 | } 56 | }, 57 | "strip-ansi": { 58 | "version": "5.2.0", 59 | "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", 60 | "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", 61 | "requires": { 62 | "ansi-regex": "^4.1.0" 63 | } 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "javascript-project", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "project.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "prompt-sync": "^4.2.0" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /project.js: -------------------------------------------------------------------------------- 1 | // 1. Despot some money 2 | // 2. Determine number of lines to bet on 3 | // 3. Collect a bet amount 4 | // 4. Spin the slot machine 5 | // 5. check if the user won 6 | // 6. give the user their winnings 7 | // 7. play again 8 | 9 | const prompt = require("prompt-sync")(); 10 | 11 | const ROWS = 3; 12 | const COLS = 3; 13 | 14 | const SYMBOLS_COUNT = { 15 | A: 2, 16 | B: 4, 17 | C: 6, 18 | D: 8, 19 | }; 20 | 21 | const SYMBOL_VALUES = { 22 | A: 5, 23 | B: 4, 24 | C: 3, 25 | D: 2, 26 | }; 27 | 28 | const deposit = () => { 29 | while (true) { 30 | const depositAmount = prompt("Enter a deposit amount: "); 31 | const numberDepositAmount = parseFloat(depositAmount); 32 | 33 | if (isNaN(numberDepositAmount) || numberDepositAmount <= 0) { 34 | console.log("Invalid deposit amount, try again."); 35 | } else { 36 | return numberDepositAmount; 37 | } 38 | } 39 | }; 40 | 41 | const getNumberOfLines = () => { 42 | while (true) { 43 | const lines = prompt("Enter the number of lines to bet on (1-3): "); 44 | const numberOfLines = parseFloat(lines); 45 | 46 | if (isNaN(numberOfLines) || numberOfLines <= 0 || numberOfLines > 3) { 47 | console.log("Invalid number of lines, try again."); 48 | } else { 49 | return numberOfLines; 50 | } 51 | } 52 | }; 53 | 54 | const getBet = (balance, lines) => { 55 | while (true) { 56 | const bet = prompt("Enter the bet per line: "); 57 | const numberBet = parseFloat(bet); 58 | 59 | if (isNaN(numberBet) || numberBet <= 0 || numberBet > balance / lines) { 60 | console.log("Invalid bet, try again."); 61 | } else { 62 | return numberBet; 63 | } 64 | } 65 | }; 66 | 67 | const spin = () => { 68 | const symbols = []; 69 | for (const [symbol, count] of Object.entries(SYMBOLS_COUNT)) { 70 | for (let i = 0; i < count; i++) { 71 | symbols.push(symbol); 72 | } 73 | } 74 | 75 | const reels = []; 76 | for (let i = 0; i < COLS; i++) { 77 | reels.push([]); 78 | const reelSymbols = [...symbols]; 79 | for (let j = 0; j < ROWS; j++) { 80 | const randomIndex = Math.floor(Math.random() * reelSymbols.length); 81 | const selectedSymbol = reelSymbols[randomIndex]; 82 | reels[i].push(selectedSymbol); 83 | reelSymbols.splice(randomIndex, 1); 84 | } 85 | } 86 | 87 | return reels; 88 | }; 89 | 90 | const transpose = (reels) => { 91 | const rows = []; 92 | 93 | for (let i = 0; i < ROWS; i++) { 94 | rows.push([]); 95 | for (let j = 0; j < COLS; j++) { 96 | rows[i].push(reels[j][i]); 97 | } 98 | } 99 | 100 | return rows; 101 | }; 102 | 103 | const printRows = (rows) => { 104 | for (const row of rows) { 105 | let rowString = ""; 106 | for (const [i, symbol] of row.entries()) { 107 | rowString += symbol; 108 | if (i != row.length - 1) { 109 | rowString += " | "; 110 | } 111 | } 112 | console.log(rowString); 113 | } 114 | }; 115 | 116 | const getWinnings = (rows, bet, lines) => { 117 | let winnings = 0; 118 | 119 | for (let row = 0; row < lines; row++) { 120 | const symbols = rows[row]; 121 | let allSame = true; 122 | 123 | for (const symbol of symbols) { 124 | if (symbol != symbols[0]) { 125 | allSame = false; 126 | break; 127 | } 128 | } 129 | 130 | if (allSame) { 131 | winnings += bet * SYMBOL_VALUES[symbols[0]]; 132 | } 133 | } 134 | 135 | return winnings; 136 | }; 137 | 138 | const game = () => { 139 | let balance = deposit(); 140 | 141 | while (true) { 142 | console.log("You have a balance of $" + balance); 143 | const numberOfLines = getNumberOfLines(); 144 | const bet = getBet(balance, numberOfLines); 145 | balance -= bet * numberOfLines; 146 | const reels = spin(); 147 | const rows = transpose(reels); 148 | printRows(rows); 149 | const winnings = getWinnings(rows, bet, numberOfLines); 150 | balance += winnings; 151 | console.log("You won, $" + winnings.toString()); 152 | 153 | if (balance <= 0) { 154 | console.log("You ran out of money!"); 155 | break; 156 | } 157 | 158 | const playAgain = prompt("Do you want to play again (y/n)? "); 159 | 160 | if (playAgain != "y") break; 161 | } 162 | }; 163 | 164 | game(); 165 | --------------------------------------------------------------------------------