├── solution.JPG ├── index.html ├── app.js ├── LICENSE └── README.md /solution.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HackerUSA-CE/activity-5.5.1-classes-of-chance/HEAD/solution.JPG -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Classes Of Chance 4 | 5 | 6 | -------------------------------------------------------------------------------- /app.js: -------------------------------------------------------------------------------- 1 | class Casino { 2 | // Write code here 3 | }; 4 | 5 | // TESTS 6 | const myCasino = new Casino("HackerU Casino"); 7 | console.log(myCasino); 8 | myCasino.playGame(5); 9 | myCasino.playGame(15); 10 | myCasino.playGame(25); 11 | myCasino.playGame(35); 12 | 13 | // BONUS TESTS 14 | /* 15 | const myBonusCasino = new Casino("HackerU Bonus Casino", true); 16 | console.log(myBonusCasino); 17 | myBonusCasino.playGame(5); 18 | myBonusCasino.playGame(15); 19 | myBonusCasino.playGame(25); 20 | myBonusCasino.playGame(35); 21 | */ 22 | 23 | // Extra BONUS TESTS 24 | /* 25 | const myExtraBonusCasino = new Casino("HackerU Extra Bonus Casino", false); 26 | console.log(myExtraBonusCasino); 27 | myExtraBonusCasino.rollDie(6); 28 | myExtraBonusCasino.rollDie(20); 29 | myExtraBonusCasino.rollDie(100); 30 | */ 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 ThriveDX 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Activity: Classes Of Chance 2 | 3 | Create a Casino class that allows users to bet on a game of chance 4 | 5 | Opening the index.html in your browser and viewing the console should look like this when you are done and you uncomment all the tests: 6 | 7 | ![alt tag](./solution.JPG) 8 | 9 | ## Directions 10 | 11 | You just opened a casino and are introducing a brand new game of change to your customers. 12 | 13 | Our game will be a simple coin flipping game that encourages customers to play for longer by increasing the reward with each consecutive game they play. 14 | 15 | 1. Create a **Casino** class that takes a **name** as input to it's constructor. 16 | 2. Add another field called **timesPlayed** that has a default value of 0. 17 | 3. Create a method called **playGame(betAmount)** that checks if **Math.random() is less than or equal to 0.5**. If true, console.log that the name of the casino wins. If false, say the player wins the bet amount. 18 | 4. When the player wins increment the **timesPlayed** by one. Then, when the player wins, change the amount they won to equal: **betAmount * (this.timesPlayed + 1)**. 19 | 20 | ```js 21 | const myCasino = new Casino("HackerU Casino"); 22 | myCasino.playGame(5); 23 | > You won 5 dollars from HackerU Casino! 24 | myCasino.playGame(5); 25 | > You won 10 dollars at the HackerU Casino! 26 | myCasino.playGame(5); 27 | > HackerU Casino wins! 28 | ``` 29 | 30 | ### BONUS 31 | 32 | Add a **isFakeCoin** field to your class and always have the casino win every time when the isFakeCoin is set to true. 33 | 34 | ```js 35 | const myBonusCasino = new BonusCasino("HackerU Casino", true); 36 | myBonusCasino.playGame(5); 37 | > HackerU Casino wins! 38 | myBonusCasino.playGame(66); 39 | > HackerU Casino wins! 40 | myBonusCasino.playGame(66); 41 | > HackerU Casino wins! 42 | ``` 43 | 44 | ### EXTRA BONUS 45 | 46 | Add another function called **rollDie(d)** that console.logs what you get when you roll a die that has "d" sides. 47 | **NOTE**: We definitely used google to get the equation for this when we designed the curriculum. Don't be afraid to search! 48 | 49 | ```js 50 | const myEBCasino = new ExtraBonusCasino("HackerU Casino", false); 51 | myEBCasino.rollDie(); 52 | > You rolled a 2! 53 | myEBCasino.rollDie(); 54 | > You rolled a 1! 55 | myEBCasino.rollDie(); 56 | > You rolled a 3! 57 | myEBCasino.rollDie(); 58 | > You rolled a 6! 59 | myEBCasino.rollDie(); 60 | > You rolled a 5! 61 | ``` 62 | 63 | > By adding more methods and fields to this class you could simulate drawing a card from a deck, and then you could hypothetically build just about any card game with just a bit more math! 64 | --------------------------------------------------------------------------------