├── JavaScriptTab ├── css │ └── styles.css ├── icon.png ├── index.html ├── js │ └── main.js └── manifest.json ├── README.md ├── adventure └── choose-your-own-adventure.js ├── bankAccount └── oo-bank-account.js ├── battleship ├── battleship.js └── battleship.spec.js ├── bitcoin └── bitcoin.js ├── blackjack └── blackjack.js ├── breakout └── breakout.js ├── calculator ├── calculator.js └── calculator.spec.js ├── checkers └── checkers.js ├── chess └── chess.js ├── connectFour └── connect-four.js ├── digitalClock └── digital-clock.js ├── eightBall └── magic-eight-ball.js ├── hangman └── hangman.js ├── madlibs └── madlibs.js ├── mineSweeper └── minesweeper.js ├── poker └── poker.js ├── pomodoro └── pomodoro.js ├── rockPaperScissors └── rock-paper-scissors.js ├── scrabble └── scrabble.js ├── simon └── simon.js ├── snakeGame ├── index.html ├── p5.min.js ├── sketch.js └── snake.js ├── stockTrader └── stock-trader.js ├── ticTacToe └── tic-tac-toe.js ├── toDo ├── index.html ├── script.js └── style.css └── twitterClone └── twitter-clone.js /JavaScriptTab/css/styles.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: 'Oxygen', sans-serif; 3 | font-size: 22px; 4 | background-color: #204056; 5 | color: white; 6 | letter-spacing: 0.05rem; 7 | width: 100vw; 8 | height: 100vh; 9 | display: flex; 10 | justify-content: center; 11 | align-content: center; 12 | width: 40rem; 13 | margin: 10vh auto; 14 | } 15 | 16 | .tip { 17 | width: 100%; 18 | } 19 | 20 | .code { 21 | font-family: monospace; 22 | background-color: #336180; 23 | padding: 0.25rem 0.75rem; 24 | font-size: 1.375rem; 25 | border-radius: 0.15em; 26 | } 27 | 28 | .code-block { 29 | font-family: monaco, Consolas, "Lucida Console", monospace; 30 | background-color: #336180; 31 | padding: 0.5em 0.75em; 32 | font-size: 1.15rem; 33 | border-radius: 0.15rem; 34 | display: block; 35 | margin: 1rem 0; 36 | } 37 | 38 | .tip-number { 39 | margin: auto; 40 | margin-bottom: 2.5rem; 41 | color: #CCCCCC; 42 | text-transform: uppercase; 43 | letter-spacing: 0.1rem; 44 | font-weight: bolder; 45 | font-size: 1rem; 46 | } 47 | 48 | .js-tip { 49 | margin: auto; 50 | line-height: 2rem; 51 | font-weight: 300; 52 | font-size: 1.375rem 53 | } 54 | 55 | .tip-button { 56 | background-color: #34B3A0; 57 | outline: none; 58 | padding: 1rem 1.5rem; 59 | display: inline-block; 60 | margin: auto; 61 | font-size: 1rem; 62 | margin-top: 2.5rem; 63 | cursor: pointer; 64 | font-weight: bolder; 65 | border: none; 66 | color: white; 67 | } 68 | 69 | .disabled { 70 | background-color: #D8D8D8 !important; 71 | color: #888; 72 | cursor: not-allowed !important; 73 | } 74 | -------------------------------------------------------------------------------- /JavaScriptTab/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/strongdan/beginner-js-projects/bc7a1f9f595e18d1ca37883d1330f7d4c42762b5/JavaScriptTab/icon.png -------------------------------------------------------------------------------- /JavaScriptTab/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Tips Tab 5 | 6 | 7 | 8 | 9 | 10 |
11 |
12 | JavaScript Tip 13 |
14 | 15 |
16 | 17 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /JavaScriptTab/js/main.js: -------------------------------------------------------------------------------- 1 | // List of JavaScript tips 2 | var tipsList = [ 3 | "Don't forget the var keyword when assigning a variable's value for the first time.", 4 | 5 | "undefined, null, 0, false, NaN, and '' (empty string) are all falsy.", 6 | 7 | "Declare a function with
function myFunctionName() {
  ...
}
", 8 | 9 | "if/else statements look like
if (condition) {
  ...
} else {
  ...
}", 10 | 11 | "You can return the result of a function into a variable with return:
function timesFive(inputNumber) {
  return inputNumber * 5;
}
console.log(timesFive(6));
// Output: 30
", 12 | 13 | "The && operator means both things must be true:
true && true = true
true && false = false
false && false = false
", 14 | 15 | "The || operator means either can be true:
true || true = true
true || false = true
false || false = false
", 16 | 17 | "A for has three condtions: a start condition, a stop condition, and an iterator:
for (var i = 0; i < myArray.length; i++) {
  ...
}
", 18 | 19 | "To interpolate a variable into a string, use the + operator, like this:
var myName = 'Jon';
'Hello, my name is ' + myName;
", 20 | 21 | "To generate a random number, use JavaScript's built in function Math.random().", 22 | 23 | "Arrays hold lists of data. You can access any of the list items by using bracket notation, like this:
var myArray = ['pears', 'asparagus', 'bananas'];
myArray[1]; // asparagus
" 24 | ]; 25 | 26 | // Tip Limit counter 27 | 28 | 29 | // Generate a number 30 | 31 | 32 | // Generate a tip: 33 | // 1. Get random number from generateNumber() 34 | // 2. Use the random number to get the tip from the array 35 | // 3. Show the tip 36 | 37 | 38 | // Tip button click 39 | // 1. Select the tip button 40 | // 2. Add a click event listener 41 | // 3. When the button is clicked: 42 | // 3a. Subtract 1 from the tipLimit 43 | // 3b. If the tipLimit is still above or equal to 0, generate a new tip 44 | // 3c. If not, change the button text and look 45 | 46 | 47 | // Get the first tip 48 | -------------------------------------------------------------------------------- /JavaScriptTab/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "JavaScript Tips Tab", 3 | "manifest_version": 2, 4 | "description": "Codecademy JavaScript tips when you open a new tab in Chrome", 5 | "version": "0.0.0.1", 6 | "permissions": ["management"], 7 | "chrome_url_overrides": { 8 | "newtab": "index.html" 9 | }, 10 | "icons": { 11 | "128": "icon.png" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Beginner Programming Ideas 2 | ## Project Ideas for Beginning JavaScript Programmers with sample code provided in .js files 3 | 4 | ### Simple Projects 5 | - [ ] [Adventure Game](https://knightlab.northwestern.edu/2014/06/05/five-mini-programming-projects-for-the-python-beginner/) 6 | - [X] [Analog Clock](https://github.com/strongdan/js-analog-clock/) 7 | - [ ] Battleship Game 8 | - [ ] Bitcoin game: "buy" Bitcoin and watch its performance over time 9 | - [ ] Bitcoin price notifier (like [Real Python's Python Project for Beginners: Bitcoin Price Notifications](https://realpython.com/blog/python/python-bitcoin-ifttt/)) 10 | - [ ] Blackjack Game 11 | - [ ] Breakout Game (based on [MDN tutorial](https://developer.mozilla.org/en-US/docs/Games/Tutorials/2D_Breakout_game_pure_JavaScript) - code available on [Github](https://github.com/end3r/Gamedev-Canvas-workshop)) 12 | - [X] Calculator App 13 | - [ ] Custom Welcome Messages 14 | - [ ] Digital Clock 15 | - [ ] Dynamic Typing Test 16 | - [ ] Checkers Game 17 | - [ ] Chess Game 18 | - [ ] Choose Your Own Adventure story game 19 | - [ ] Connect Four Game 20 | - [ ] [Dice Rolling Simulator](https://knightlab.northwestern.edu/2014/06/05/five-mini-programming-projects-for-the-python-beginner/) 21 | - [ ] [Guess the Number](https://knightlab.northwestern.edu/2014/06/05/five-mini-programming-projects-for-the-python-beginner/) 22 | - [ ] Hangman Game 23 | - [ ] [JavaScript Tips Tab](https://medium.com/@codecademy/javascript-tips-tab-4e9081b4132) (Credit @Codecademy) 24 | - [X] [Lighthouse Labs](https://github.com/lighthouse-labs) [21-Day Coding Challenge](https://coding-challenge.lighthouselabs.ca/start) 25 | - [ ] [Mad Libs Generator](https://knightlab.northwestern.edu/2014/06/05/five-mini-programming-projects-for-the-python-beginner/) 26 | - [X] Magic Eight Ball 27 | - [ ] [Mario 3 Memory Game](https://github.com/strongdan/memory-game) (credit [@taniarascia](https://github.com/taniarascia)) 28 | - [ ] Piano Keyboard (see [Joe Liang's walkthrough](https://www.freecodecamp.org/news/javascript-piano-keyboard/)) 29 | - [ ] Poker Game 30 | - [X] [Random Quote Generator](https://github.com/strongdan/freeCodeCamp-random-quote-generator) 31 | - [X] Rock-Paper-Scissors Game 32 | - [ ] Play Audio Webpage 33 | - [ ] Pomodoro Clock 34 | - [ ] digital children game 35 | - [ ] Scrabble Clone 36 | - [ ] Stock trading simulator: users pick a stock or mutual fund, to "buy" and watch its performance (recommend using [IEX API](https://iextrading.com/developer/docs/) - can use [Todd Schneider's stock page](https://github.com/toddwschneider/stocks) as a reference) 37 | - [ ] Simon Game 38 | - [ ] Tic-tac-toe game 39 | - [ ] Tip Calculator 40 | - [ ] Twitter Clone 41 | - [X] [Typing Speed Test](https://github.com/strongdan/js-typing-speed-test/) 42 | - [ ] Today's Horoscope 43 | 44 | ### Object-oriented Projects 45 | - [ ] Bank account 46 | - [ ] Checkers 47 | - [ ] Chess 48 | - [ ] Minesweeper 49 | - [ ] Tic-Tac-Toe 50 | 51 | ### Basic CRUD Projects 52 | - [ ] [Simple CRUD Database App](https://www.taniarascia.com/create-a-simple-database-app-connecting-to-mysql-with-php/) (credit [@taniarascia](https://github.com/taniarascia)) 53 | - [ ] Ecommerce Store 54 | - [ ] Hangman Game 55 | - [ ] Mad Libs app 56 | - [ ] Meme Generator 57 | - [ ] Movie Review Apps 58 | - [ ] Music Library 59 | - [ ] Note Taking App 60 | - [ ] [MVC Todo App](https://www.taniarascia.com/javascript-mvc-todo-app/) (credit [@taniarascia](https://github.com/taniarascia)) 61 | - [ ] Twitter Clone 62 | - [ ] Trello Clone - see Indrek Lasn's [example](https://github.com/wesharehoodies/simple-trello) 63 | - [ ] User admin dashboard - see Indrek Lasn's [example](https://github.com/wesharehoodies/laravel-5.4-crud-example) 64 | - [ ] Cryptocurrency tracker (native mobile app) - see Indrek Lasn's [post](https://medium.com/react-native-training/bitcoin-ripple-ethereum-price-checker-with-react-native-redux-e9d076037092) 65 | - [ ] Hackernews clone - use [HackerNews API](https://github.com/HackerNews/API) 66 | - [ ] Sortable drag and drop list 67 | - [ ] Messenger clone (native app) 68 | 69 | ### Projects Using Libraries 70 | - [ ] [Snake Game Built with P5.js](http://danstrong.tech/beginner-js-projects/snakeGame/) 71 | - [ ] [React QuizBuilder](https://medium.com/@dtkatz/10-react-starter-project-ideas-to-get-you-coding-5b35782e1831) 72 | - [ ] [React MusicPlayer](https://medium.com/@dtkatz/10-react-starter-project-ideas-to-get-you-coding-5b35782e1831) 73 | - [ ] [React MemeGenerator](https://medium.com/@dtkatz/10-react-starter-project-ideas-to-get-you-coding-5b35782e1831) 74 | - [ ] [React InstagramRatio](https://medium.com/@dtkatz/10-react-starter-project-ideas-to-get-you-coding-5b35782e1831) 75 | - [ ] [React TweetDeck](https://medium.com/@dtkatz/10-react-starter-project-ideas-to-get-you-coding-5b35782e1831) 76 | - [ ] [React GoofyYelp](https://medium.com/@dtkatz/10-react-starter-project-ideas-to-get-you-coding-5b35782e1831) 77 | - [ ] [React EventFinder](https://medium.com/@dtkatz/10-react-starter-project-ideas-to-get-you-coding-5b35782e1831) 78 | - [ ] [React CustomForum](https://medium.com/@dtkatz/10-react-starter-project-ideas-to-get-you-coding-5b35782e1831) 79 | - [ ] [React MyMedium](https://medium.com/@dtkatz/10-react-starter-project-ideas-to-get-you-coding-5b35782e1831) 80 | - [ ] [React Tetris](https://www.freecodecamp.org/news/react-hooks-tetris-game/) 81 | - [ ] [React YoutubeDirect](https://medium.com/@dtkatz/10-react-starter-project-ideas-to-get-you-coding-5b35782e1831) 82 | -------------------------------------------------------------------------------- /adventure/choose-your-own-adventure.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | const printStory = () => { 4 | // present user with storyline based on their choice 5 | } 6 | 7 | const queryUser = () => { 8 | // ask user how they would like to proceed 9 | } 10 | 11 | const startGame = () => { 12 | // initiate game play 13 | printFirstStory(); 14 | } 15 | -------------------------------------------------------------------------------- /bankAccount/oo-bank-account.js: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /battleship/battleship.js: -------------------------------------------------------------------------------- 1 | const ships = { 'carrier' : 5, 2 | 'battleship' : 4, 3 | 'cruiser' : 3, 4 | 'submarine' : 3, 5 | 'destroyer' : 2 } 6 | 7 | let board1 = [ [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], 8 | [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], 9 | [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], 10 | [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], 11 | [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], 12 | [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], 13 | [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], 14 | [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], 15 | [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], 16 | [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '] ]; 17 | let board2 = [ [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], 18 | [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], 19 | [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], 20 | [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], 21 | [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], 22 | [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], 23 | [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], 24 | [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], 25 | [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], 26 | [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '] ]; 27 | 28 | let shipPositionsUser1 = {}; // tracks which squares have a ship on them 29 | let shipPositionsUser2 = {}; 30 | 31 | const userTurn = (previousUser) => { 32 | // switches turns between 1 and 2 33 | if (previousUser === 1) { 34 | return 2; 35 | } else { 36 | return 1; 37 | } 38 | } 39 | 40 | const resetBoard = () => { 41 | // resets both user's board 42 | board1.forEach(function(row) { 43 | row.forEach(function(el) { 44 | el = ' '; 45 | }); 46 | }); 47 | board2.forEach(function(row) { 48 | row.forEach(function(el) { 49 | el = ' '; 50 | }); 51 | }); 52 | shipPositionsUser1 = {}; 53 | shipPositionsUser2 = {}; 54 | } 55 | 56 | const showBoard = (user) => { 57 | // print grid with ships to console 58 | console.log(`${board}user`); 59 | } 60 | 61 | const shipsRemaining = (user) => { 62 | // list remaining ships and their length 63 | } 64 | 65 | const placeShip = (user, ship, positionStart, positionEnd) => { 66 | // allows user to place five ships on board 67 | // checks whether ship is already present and ensures ship doesn't extend off board 68 | } 69 | 70 | const fireShot = (position) => { 71 | // allows user to select position on board to fire at (eg. A1) 72 | // updates board with Xs for hits, Os for misses 73 | } 74 | 75 | const hitOrNot = () => { 76 | // checks whether shots hit a ship or not and notifies other user 77 | // updates shipPositions object with Xs for hit ships 78 | } 79 | 80 | const sunkShip = (user) => { 81 | // checks whether entire ship has been destroyed and alerts user 82 | } 83 | 84 | const gameWon = () => { 85 | // checks whether game has been won and prints winner 86 | if (shipsRemaining(1) === 0) { 87 | console.log(`${user2} won!`); 88 | return true; 89 | } else if (shipsRemaining(2) === 0) { 90 | console.log(`${user2} won!`); 91 | return true; 92 | } else { 93 | return false; 94 | } 95 | } 96 | 97 | const playGame = () => { 98 | // starts new game 99 | resetBoard(); 100 | placeShip(1); 101 | placeShip(2); 102 | user = Math.floor(Math.random() * 2; // chooses a random user to start 103 | console.log(`User ${user) + 1} starts!`); 104 | while (!gameWon()) { 105 | showBoard(user); 106 | fireShot(position); 107 | hitOrNot(position); 108 | console.log(sunkShip(user)); 109 | console.log(shipsRemaining(user)); 110 | user = userTurn(user); 111 | } 112 | gameWon(); 113 | playGame(); 114 | } 115 | 116 | playGame(); 117 | 118 | 119 | 120 | module.exports = { 121 | userTurn, 122 | resetBoard, 123 | showBoard, 124 | shipsRemaining, 125 | placeShip, 126 | fireShot, 127 | hitOrNot, 128 | sunkShip, 129 | gameWon, 130 | playGame 131 | } 132 | -------------------------------------------------------------------------------- /battleship/battleship.spec.js: -------------------------------------------------------------------------------- 1 | require('./battleship.js'); 2 | 3 | describe('userTurn', function() { 4 | it('switches turns between 1 and 2', function() { 5 | expect(userTurn(1)).toEqual(2); 6 | }); 7 | }); 8 | 9 | describe('userTurn', function() { 10 | it('switches turns between 1 and 2', function() { 11 | expect(userTurn(2)).toEqual(1); 12 | }); 13 | }); 14 | 15 | describe('resetBoard', function() { 16 | it('resets both user\'s board', function() { 17 | expect(resetBoard()).toEqual(); 18 | }); 19 | }); 20 | 21 | describe('shipsRemaining', function() { 22 | it('lists remaining ships and their length', function() { 23 | expect(shipsRemaining()).toEqual(); 24 | }); 25 | }); 26 | 27 | describe('placeShip', function() { 28 | it('checks whether ship is already present and ensures ship doesn\'t extend off board', function() { 29 | expect(placeShip()).toEqual(); 30 | }); 31 | }); 32 | 33 | describe('fireShot', function() { 34 | it('updates board with Xs for hits, Os for misses', function() { 35 | expect(fireShot()).toEqual(); 36 | }); 37 | }); 38 | 39 | describe('hitOrNot', function() { 40 | it('checks whether shots hit a ship or not and notifies other user', function() { 41 | expect(hitOrNot()).toEqual(); 42 | }); 43 | }); 44 | 45 | describe('sunkShip', function() { 46 | it('checks whether entire ship has been destroyed and alerts user', function() { 47 | expect(sunkShip()).toEqual(); 48 | }); 49 | }); 50 | 51 | describe('gameWon', function() { 52 | it('checks whether game has been won and prints winner', function() { 53 | expect(gameWon()).toEqual(); 54 | }); 55 | }); 56 | 57 | describe('playGame', function() { 58 | it('starts and plays through game', function() { 59 | expect(playGame()).toEqual(); 60 | }); 61 | }); 62 | -------------------------------------------------------------------------------- /bitcoin/bitcoin.js: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /blackjack/blackjack.js: -------------------------------------------------------------------------------- 1 | let currentScore = 0; 2 | const cards = {'two' : 2, 3 | 'three' : 3, 4 | 'four' : 4, 5 | 'five' : 5, 6 | 'six' : 6, 7 | 'seven' : 7, 8 | 'eight' : 8, 9 | 'nine' : 9, 10 | 'ten' : 10, 11 | 'jack' : 10, 12 | 'queen' : 10, 13 | 'king' : 10, 14 | 'ace' : [1, 11] } 15 | 16 | const randomCard = (cards) => { 17 | // random value between 1 and 13 (size of object) 18 | let randNum = Math.floor(Math.random() * 14) 19 | // returns random element from cards as an array 20 | if (Object.keys(cards)[randNum] === 'ace') { 21 | return Object.keys(cards)[randNum][Math.floor(Math.random())]; 22 | } 23 | return Object.keys(cards)[randNum]; 24 | } 25 | 26 | const initialDeal = () => { 27 | // deals two cards to start the game 28 | card1 = randomCard(cards); 29 | card2 = randomCard(cards); 30 | // returns object with card names and values 31 | return { card1, card2 }; 32 | } 33 | 34 | const dealCard = () => { 35 | // if user requests additional card, card is drawn and score is incremented 36 | let newCard = randomCard(cards); 37 | // returns card and value 38 | return { newCard } 39 | } 40 | 41 | const playGame = () => { 42 | console.log('Welcome to blackjack!'); 43 | firstCards = initialDeal(); 44 | currentScore += firstCards[card1].val + firstCards[card2].val; 45 | console.log(`Your first cards are: ${firstCards[card1]} and ${firstCards[card2]}); 46 | console.log(`Your score is ${currentScore}); 47 | dealCard(); 48 | } 49 | 50 | 51 | 52 | 53 | playGame(); 54 | -------------------------------------------------------------------------------- /breakout/breakout.js: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /calculator/calculator.js: -------------------------------------------------------------------------------- 1 | // allows basic arithmetic operations - including addition, subtraction, multiplication and division 2 | const add = (num1, num2) => { 3 | return Number(num1) + Number(num2); 4 | } 5 | 6 | const subtract = (num1, num2) => { 7 | return Number(num1) - Number(num2); 8 | } 9 | 10 | const multiply = (num1, num2) => { 11 | return Number(num1) * Number(num2); 12 | } 13 | 14 | const divide = (num1, num2) => { 15 | if (Number(num2) === 0) { 16 | console.log('You cannot divide by zero'); 17 | } else { 18 | return Number(num1) / Number(num2); 19 | } 20 | } 21 | 22 | const getUserInput = () => { 23 | console.log('Welcome! You can add, subtract, multiply or divide...'); 24 | let num1 = prompt('Please enter your first number.'); 25 | let operator = prompt('Please enter + for addition, - for subtraction, * for multiplication or / for division'); 26 | if (['+', '-', '*', '/'].indexOf(operator) < 0) { 27 | console.log('Please enter a valid operator'); 28 | getUserInput(); 29 | } 30 | let num2 = prompt('Please enter your second number'); 31 | return [num1, operator, num2]; 32 | } 33 | 34 | const calculate = () => { 35 | let values = getUserInput(); 36 | let num1 = values[0].trim(); 37 | let operator = values[1].trim(); 38 | let num2 = values[2].trim(); 39 | if (operator === '+') { 40 | alert(`Your answer is ${add(num1, num2)}`); 41 | return add(num1, num2); 42 | } else if (operator === '-') { 43 | alert(`Your answer is ${subtract(num1, num2)}`); 44 | return subtract(num1, num2); 45 | } else if (operator === '*') { 46 | alert(`Your answer is ${multiply(num1, num2)}`); 47 | return multiply(num1, num2); 48 | } else if (operator === '/') { 49 | alert(`Your answer is ${divide(num1, num2)}`); 50 | return divide(num1, num2); 51 | } else { 52 | console.log('Please enter a valid operator'); 53 | } 54 | } 55 | 56 | calculate(); 57 | 58 | module.exports = { 59 | calculate, 60 | getUserInput, 61 | add, 62 | subtract, 63 | multiply, 64 | divide, 65 | } 66 | -------------------------------------------------------------------------------- /calculator/calculator.spec.js: -------------------------------------------------------------------------------- 1 | require('./calculator.js'); 2 | 3 | describe('add', function() { 4 | it('adds two numbers', function() { 5 | expect(add(10, 42)).toEqual(52); 6 | }); 7 | }); 8 | 9 | describe('add', function() { 10 | it('adds two numbers', function() { 11 | expect(add(101, 5)).toEqual(106); 12 | }); 13 | }); 14 | 15 | describe('subtract', function() { 16 | it('subtracts two numbers', function() { 17 | expect(subtract(10, 42)).toEqual(-38); 18 | }); 19 | }); 20 | 21 | describe('subtract', function() { 22 | it('subtracts two numbers', function() { 23 | expect(subtract(42, 10)).toEqual(32); 24 | }); 25 | }); 26 | 27 | describe('multiply', function() { 28 | it('multiplies two numbers', function() { 29 | expect(multiply(10, 42)).toEqual(420); 30 | }); 31 | }); 32 | 33 | describe('multiply', function() { 34 | it('multiplies two numbers', function() { 35 | expect(multiply(101, 5)).toEqual(505); 36 | }); 37 | }); 38 | 39 | describe('divide', function() { 40 | it('divides two numbers', function() { 41 | expect(divide(10, 42)).toEqual(0.23809523809523808); 42 | }); 43 | }); 44 | 45 | describe('divide', function() { 46 | it('divides two numbers', function() { 47 | expect(divide(42, 10)).toEqual(4.2); 48 | }); 49 | }); 50 | 51 | describe('divide', function() { 52 | it('divides two numbers', function() { 53 | expect(divide(10, 0)).toEqual('You cannot divide by zero'); 54 | }); 55 | }); 56 | -------------------------------------------------------------------------------- /checkers/checkers.js: -------------------------------------------------------------------------------- 1 | let startingBoard = [ [ 0, 1, 0, 1, 0, 1, 0, 1 ], 2 | [ 1, 0, 1, 0, 1, 0, 1, 0 ], 3 | [ 0, 1, 0, 1, 0, 1, 0, 1 ], 4 | [ 0, 0, 0, 0, 0, 0, 0, 0 ], 5 | [ 0, 0, 0, 0, 0, 0, 0, 0 ], 6 | [ 2, 0, 2, 0, 2, 0, 2, 0 ], 7 | [ 0, 2, 0, 2, 0, 2, 0, 2 ], 8 | [ 2, 0, 2, 0, 2, 0, 2, 0 ] ]; 9 | 10 | let userOneCheckers = []; 11 | let userTwoCheckers = []; 12 | 13 | const startGame = () => { 14 | // set up game board in starting position 15 | let board = startingBoard; 16 | return board; 17 | } 18 | 19 | const firstUser = () => { 20 | // returns first user randomly 21 | let user = Math.floor(Math.random() * 2) + 1 22 | return user; 23 | } 24 | 25 | const printBoard = (board) => { 26 | // prints board with alphanumeric grid positions on the side and bottom 27 | board.forEach(function(row){ 28 | console.log(row); 29 | }); 30 | } 31 | 32 | const moveToken = () => { 33 | // allows user to move a token to a grid position 34 | 35 | } 36 | 37 | const jumpAvailable = (user, boardPosition) => { 38 | // checks if a user has a jump available at a specific position 39 | } 40 | 41 | const validMove = () => { 42 | // checks to see if move is valid 43 | // if a jump is available, user must take it 44 | } 45 | 46 | const attack = () => { 47 | // jumps other user's piece(s) and removes those pieces from the board 48 | } 49 | 50 | const kingMe = (user, boardYPosition, boardXPosition) => { 51 | // if token reaches the end of the board, it becomes a king 52 | if (user === 1 && boardYPosition === 7) { 53 | // token is changed from a number to a "K" 54 | board[boardYPosition][boardXPosition] = 'K1'; 55 | } else if (user === 2 && boardYPosition === 0) { 56 | board[boardYPosition][boardXPosition] = 'K2'; 57 | } 58 | } 59 | 60 | const switchUser = (currentUser) => { 61 | if (currentUser === 1) { 62 | return 2; 63 | } else { 64 | return 1; 65 | } 66 | } 67 | 68 | const playGame = () => { 69 | // start game and play through 70 | printBoard(startGame); 71 | console.log(`User ${firstUser()} goes first!`); 72 | 73 | } 74 | 75 | playGame(); 76 | -------------------------------------------------------------------------------- /chess/chess.js: -------------------------------------------------------------------------------- 1 | const pieces = { ['QR1', 'QN1', ''], 2 | [] }; 3 | let board = [ ['', '', '', '', '', '', '', ''], 4 | ['', '', '', '', '', '', '', ''], 5 | ['', '', '', '', '', '', '', ''], 6 | ['', '', '', '', '', '', '', ''], 7 | ['', '', '', '', '', '', '', ''], 8 | ['', '', '', '', '', '', '', ''], 9 | ['', '', '', '', '', '', '', ''], 10 | ['', '', '', '', '', '', '', ''] ]; 11 | const setupBoard = () => { 12 | // set pawns on both sides of board, with white on the bottom 13 | for (let i = 0; i < board[1].length; i++) { 14 | board[1][i] = 'BP'; 15 | } 16 | for (let j = 0; j < board[6].length; j++) { 17 | board[6][j] = 'WP'; 18 | } 19 | board[0][0] = 'BR'; // black rook left 20 | board[0][7] = 'BR'; // black rook right 21 | board[7][0] = 'WR'; // white rook left 22 | board[7][7] = 'WR'; // white rook right 23 | board[0][1] = 'BN' // black knight left 24 | board[0][6] = 'BN' // black knight right 25 | board[7][1] = 'WN' // white knight left 26 | board[7][6] = 'WN' // white knight right 27 | board[0][2] = 'BB' // black bishop left 28 | board[0][5] = 'BB' // black bishop right 29 | board[7][2] = 'WB' // white bishop left 30 | board[7][5] = 'WB' // white bishop right 31 | board[0][3] = 'BQ' // black queen 32 | board[0][4] = 'BK' // black king 33 | board[7][3] = 'WQ' // white queen 34 | board[7][4] = 'WK' // white king 35 | } 36 | let blackPieces = []; 37 | let whitePieces = []; 38 | const pawnMoves = () => { 39 | // defines valid pawn movement within the confines of the board array 40 | // includes en passant 41 | } 42 | const rookMoves = () => { 43 | // defines rook movement within the confines of the board array 44 | } 45 | const knightMoves = () => { 46 | // defines valid knight movement within the confines of the board array 47 | } 48 | const bishopMoves = () => { 49 | // defines valid bishop movement within the confines of the board array 50 | } 51 | const queenMoves = () => { 52 | // defines valid queen movement within the confines of the board array 53 | } 54 | const kingMoves = () => { 55 | // defines valid king movement within the confines of the board array 56 | } 57 | const castling = () => { 58 | // establishes valid rules for castling 59 | } 60 | const squareTaken = () => { 61 | // checks whether a square is occupied and returns true or false 62 | } 63 | const checkOrCheckmate = () => { 64 | // check if king is in check or checkmate 65 | } 66 | const playGame = () => { 67 | // starts game and plays through until a stalemate or win 68 | setupBoard(); 69 | blackPieces.push(); 70 | whitePieces.push(); 71 | } 72 | -------------------------------------------------------------------------------- /connectFour/connect-four.js: -------------------------------------------------------------------------------- 1 | let board = [ [' ', ' ', ' ', ' ', ' ', ' '], 2 | [' ', ' ', ' ', ' ', ' ', ' '], 3 | [' ', ' ', ' ', ' ', ' ', ' '], 4 | [' ', ' ', ' ', ' ', ' ', ' '], 5 | [' ', ' ', ' ', ' ', ' ', ' '], 6 | [' ', ' ', ' ', ' ', ' ', ' '], 7 | [' ', ' ', ' ', ' ', ' ', ' '], 8 | [' ', ' ', ' ', ' ', ' ', ' '] ]; 9 | 10 | const startPlayer = () => { 11 | return Math.floor(Math.random() * 2) + 1; // player 1 or 2 12 | } 13 | 14 | const switchPlayer = (currentPlayer) => { 15 | // switches between players 16 | if (player === 1) { 17 | return 2; 18 | } else { 19 | return 1; 20 | } 21 | } 22 | 23 | const newGame = () => { 24 | // clear board for a new game 25 | for (let i = 0; i < board.length; i++) { 26 | for (let j = 0; j < board[i].length; j++) { 27 | board[i][j] = '__'; 28 | } 29 | } 30 | } 31 | 32 | const printBoard = () => { 33 | // prints out current board 34 | let yCoord = 7; 35 | for (let i = 0; i < board.length; i++) { 36 | console.log(`${yCoord} - \t${board[i]}`); 37 | yCoord -= 1; 38 | } 39 | console.log(['A', 'B', 'C', 'D', 'E', 'F', 'G']); 40 | } 41 | 42 | const playToken = (column, token) => { 43 | // player inserts player token on board at specified column, A-G 44 | // if token exists in column, new token is inserted at one index less 45 | } 46 | 47 | const tokenExists = (x, y) => { 48 | // checks to see if token is in specified column 49 | if (board[y][x] !== '') { 50 | return true; 51 | } else { 52 | return false; 53 | } 54 | } 55 | 56 | const columnFull = () => { 57 | // returns true if column filled with tokens 58 | } 59 | 60 | const wonGame = () => { 61 | let player1 = 0; 62 | let player2 = 0; 63 | // checks for four-in-a-row vertically 64 | 65 | // checks for four-in-a-row horizontally 66 | for (let j = 0; j < board.length; j++) { 67 | for (let k = 0; k < board[j].length; k++) { 68 | if (el === 1) { 69 | player1 += 1; 70 | } else if (el === 2) { 71 | player2 += 1; 72 | } 73 | } 74 | } 75 | 76 | // checks for four-in-a-row diagonally 77 | 78 | // returns true for won game, false otherwise 79 | if (player1 === 4) { 80 | console.log('Player 1 won!'); 81 | return true; 82 | } else if (player2 === 4) { 83 | console.log('Player 2 won!'); 84 | return true; 85 | } else { 86 | return false; 87 | } 88 | } 89 | 90 | const playGame = () => { 91 | // start new game 92 | newGame(); 93 | // initiate new players for game 94 | let currentPlayer = startPlayer(); 95 | while (!gameWon()) { 96 | console.log(`Player ${player}, it\'s your turn.`); 97 | printBoard(); 98 | let column = prompt('Please enter a column to place your token'); 99 | if (!columnFull()) { 100 | playToken(column, currentPlayer) 101 | } else { 102 | column = prompt('Please choose a column that\'s not full'); 103 | printBoard(); 104 | playToken(); 105 | } 106 | switchPlayer(player); 107 | } 108 | console.log(`Player ${currentPlayer} won!`); 109 | newGame(); 110 | playGame(); 111 | } 112 | -------------------------------------------------------------------------------- /digitalClock/digital-clock.js: -------------------------------------------------------------------------------- 1 | const standardOrTwentyFourHour = () => { 2 | // prompts user for preference of clock format - 24hr or standard 3 | } 4 | 5 | const getCurrentTime = () => { 6 | // gets current time and returns it in datetime format 7 | let now = new Date(); 8 | return now; 9 | } 10 | 11 | const displayClock = () => { 12 | // appends clock digits to main div in window 13 | } 14 | 15 | displayClock(); 16 | -------------------------------------------------------------------------------- /eightBall/magic-eight-ball.js: -------------------------------------------------------------------------------- 1 | let userName = prompt('Please enter your name', ''); 2 | let userQuestion = prompt('Please enter your question:', ''); 3 | let randomNumber = Math.floor(Math.random() * 8); 4 | let eightBall = ''; 5 | 6 | userName ? console.log(`Hello, ${userName}`) : console.log('Hello!'); 7 | 8 | switch(randomNumber) { 9 | case 0: 10 | eightBall = 'It is certain'; 11 | break; 12 | case 1: 13 | eightBall = 'It is decidedly so'; 14 | break; 15 | case 2: 16 | eightBall = 'Reply hazy. Try again'; 17 | break; 18 | case 3: 19 | eightBall = 'Cannot predict now'; 20 | break; 21 | case 4: 22 | eightBall = 'Don\'t count on it'; 23 | break; 24 | case 5: 25 | eightBall = 'My sources say no'; 26 | break; 27 | case 6: 28 | eightBall = 'Outlook not so good'; 29 | break; 30 | case 7: 31 | eightBall = 'Signs point to yes'; 32 | break; 33 | } 34 | 35 | console.log(`${userName}'s question: ${userQuestion}`); 36 | console.log(`Eight ball's answer: ${eightBall}`); 37 | -------------------------------------------------------------------------------- /hangman/hangman.js: -------------------------------------------------------------------------------- 1 | const newHangman = [ [ ' ----------- ' ], 2 | [ ' | | ' ], 3 | [ ' | | ' ], 4 | [ ' | ' ], 5 | [ ' | ' ], 6 | [ ' | ' ], 7 | [ ' | ' ], 8 | [ ' | ' ] ]; 9 | 10 | const completedHangman = [ [ ' ----------- ' ], 11 | [ ' | | ' ], 12 | [ ' | | ' ], 13 | [ ' | O ' ], 14 | [ ' | /|\ ' ], 15 | [ ' | | ' ], 16 | [ ' | / \ ' ], 17 | [ ' | ' ] ]; 18 | 19 | const hangmanWords = ['jazz', 20 | 'buzz', 21 | 'jazzed', 22 | 'jazzy', 23 | 'buzzed', 24 | 'fuzz', 25 | 'jinx', 26 | 'fizz', 27 | 'buzzing', 28 | 'fuzzy', 29 | 'puff', 30 | 'jiff', 31 | 'buff', 32 | 'quiz', 33 | 'huff', 34 | 'zine', 35 | 'duff', 36 | 'zit' ]; 37 | 38 | const getNewWord = () => { 39 | // retrieve random word from hangmanWords 40 | return hangmanWords[Math.floor(Math.random() * hangmanWords.length)]; 41 | } 42 | 43 | const guessLetter = (word) => { 44 | // allows user to guess letter and returns true or false based on current word 45 | let letter = prompt('Please guess a letter.'); 46 | return word.includes(letter); 47 | } 48 | 49 | const printHangman = (hangmanArray) => { 50 | // print playHangman array 51 | console.log(hangmanArray); 52 | } 53 | 54 | const printBlankWord = (word) => { 55 | // print blanks for current word 56 | word = word.split(''); 57 | for (let i = 0; i < word.length; i++) { 58 | word[i] = '_'; 59 | } 60 | return word.join(''); 61 | } 62 | 63 | const addToHangman = () => { 64 | // add new element to hangman 65 | } 66 | 67 | const fillWord = (word, guessLetter = '') => { 68 | // add correctly guessed letter to blanks 69 | let blankWord = printBlankWord(word); 70 | if (guessLetter()) { 71 | // if letter is correct, fill in blanks 72 | word.split('').forEach(function(letter) { 73 | if (!letter === guessLetter) { 74 | letter = letter.replace('_'); 75 | } 76 | }); 77 | } 78 | word = word.join(''); 79 | printWord(word); 80 | return word; 81 | } 82 | 83 | const wonGame = () => { 84 | // checks if word is complete 85 | return (word.length === fillWord()); 86 | } 87 | } 88 | 89 | const lostGame = (playHangman) => { 90 | // checks whether playHangman equal to completedHangman 91 | return playHangman === completedHangman; 92 | } 93 | 94 | const playGame = () => { 95 | // starts game and plays through to end 96 | let playHangman = newHangman; 97 | let word = getNewWord(); 98 | while (!wonGame()) { 99 | printHangman(playHangman); 100 | printBlankWord(word); 101 | guessLetter(); // users get seven guesses 102 | if (!guessLetter()) { 103 | if (lostGame(playHangman)) { 104 | printHangman(playHangman); 105 | console.log('Sorry. You lost.'); 106 | break; 107 | } 108 | } else { 109 | fillWord(word); 110 | printHangman(playHangman); 111 | } 112 | } 113 | printHangman(playHangman); 114 | console.log('You won!'); 115 | playGame() 116 | } 117 | 118 | playGame(); 119 | -------------------------------------------------------------------------------- /madlibs/madlibs.js: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /mineSweeper/minesweeper.js: -------------------------------------------------------------------------------- 1 | class Board { 2 | constructor(numberOfRows, numberOfColumns, numberOfBombs) { 3 | this._numberOfRows = numberOfRows; 4 | this._numberOfColumns = numberOfColumns; 5 | this._numberOfBombs = numberOfBombs; 6 | this._numberOfTiles = numberOfRows * numberOfColumns; 7 | this._playerBoard = Board.generatePlayerBoard(numberOfRows, numberOfColumns); 8 | this._bombBoard = Board.generateBombBoard(numberOfRows, numberOfColumns); 9 | } 10 | 11 | get playerBoard() { 12 | return this._playerBoard; 13 | } 14 | 15 | flipTile(rowIndex, columnIndex) { 16 | if (this._playerBoard[rowIndex][columnIndex] !== ' ') { 17 | console.log('This tile has already been flipped!'); 18 | return; 19 | } else if (bombBoard[rowIndex][columnIndex] === 'B') { 20 | this._playerBoard[rowIndex][columnIndex] = 'B'; 21 | } else { 22 | this._playerBoard[rowIndex][columnIndex] = this.getNumberOfNeighborBombs(rowIndex, columnIndex); 23 | } 24 | this._numberOfTiles--; 25 | } 26 | 27 | getNumberOfNeighborBombs(rowIndex, columnIndex) { 28 | let neighborOffsets = [ [-1,-1], [-1,0], [-1,1], [0,-1], [0,1], [1,-1], [1,0], [1,1] ]; 29 | let numberOfRows = this._bombBoard.length; 30 | let numberOfColumns = this._bombBoard[0].length; 31 | this._numberOfBombs = 0; 32 | neighborOffsets.forEach(offset => { 33 | let neighborRowIndex = rowIndex + offset[0]; 34 | let neighborColumnIndex = columnIndex + offset[1]; 35 | if (neighborRowIndex >= 0 && neighborRowIndex <= this._numberOfRows && neighborColumnIndex >= 0 && neighborColumnIndex <= this._numberOfColumns) { 36 | if (this._bombBoard[neighborRowIndex][neighborColumnIndex] === 'B') { 37 | this._numberOfBombs += 1; 38 | } 39 | } 40 | }); 41 | return this._numberOfBombs; 42 | } 43 | } 44 | 45 | 46 | 47 | 48 | 49 | const generatePlayerBoard = (numberOfRows, numberOfColumns) => { 50 | let board = []; 51 | for (let i = 0; i < numberOfRows; i++) { 52 | let row = []; 53 | for (let j = 0; j < numberOfColumns; j++) { 54 | row.push(' '); 55 | } 56 | board.push(row); 57 | } 58 | return board; 59 | }; 60 | 61 | const generateBombBoard = (numberOfRows, numberOfColumns, numberOfBombs) => { 62 | let board = []; 63 | for (let i = 0; i < numberOfRows; i++) { 64 | let row = []; 65 | for (let j = 0; j < numberOfColumns; j++) { 66 | row.push(null); 67 | } 68 | board.push(row); 69 | } 70 | 71 | let numberOfBombsPlaced = 0; 72 | while (numberOfBombsPlaced <= numberOfBombs) { 73 | // This code has the potential to place bombs on top of already existing bombs 74 | let randomRowIndex = Math.floor(Math.random() * numberOfRows); 75 | let randomColumnIndex = Math.floor(Math.random() * numberOfColumns); 76 | if (board[randomRowIndex][randomColumnIndex] !== 'B') { 77 | board[randomRowIndex][randomColumnIndex] = 'B'; 78 | numberOfBombsPlaced += 1; 79 | } 80 | } 81 | return board; 82 | }; 83 | 84 | const printBoard = (board) => { 85 | console.log(board.map(row => row.join(' | ')).join('\n')); 86 | }; 87 | 88 | let playerBoard = generatePlayerBoard(3,4); 89 | let bombBoard = generateBombBoard(3,4,5); 90 | 91 | //flipTile(playerBoard, bombBoard, 0, 0); 92 | console.log('Updated Player Board'); 93 | printBoard(playerBoard); 94 | -------------------------------------------------------------------------------- /poker/poker.js: -------------------------------------------------------------------------------- 1 | const cards = { 'hearts': [ 2, 3, 4, 5, 6, 7, 8, 9, 10, 'J', 'Q', 'K', 'A' ], 2 | 'diamonds': [ 2, 3, 4, 5, 6, 7, 8, 9, 10, 'J', 'Q', 'K', 'A' ], 3 | 'spades': [ 2, 3, 4, 5, 6, 7, 8, 9, 10, 'J', 'Q', 'K', 'A' ], 4 | 'clubs': [ 2, 3, 4, 5, 6, 7, 8, 9, 10, 'J', 'Q', 'K', 'A' ] } 5 | 6 | const hands = [ 'Royal flush', 7 | 'Straight flush', 8 | 'Four of a kind', 9 | 'Full house', 10 | 'Flush', 11 | 'Straight', 12 | 'Three of a kind', 13 | 'Two pair', 14 | 'Pair', 15 | 'High Card' ] 16 | 17 | let playerCards = {}; 18 | let dealerCards = {}; 19 | 20 | const randNum = (low, high) => { 21 | // provides a random number between a high and low 22 | return Math.floor(Math.random() * high) + low; 23 | } 24 | 25 | const dealCards = () => { 26 | // deals five random cards to a dealer and player 27 | while (dealerCards.length <= 5) { 28 | randomSuite = cards[randNum(0,5)]; 29 | randomCard = cards[randomSuite][randNum(0, 14)] 30 | if (!playerCards.includes(randomCard)) { 31 | playerCards.push(randomCard); 32 | } 33 | } 34 | 35 | } 36 | 37 | const whichHand = () => { 38 | // checks cards to see which hand someone has 39 | } 40 | 41 | const highHand = () => { 42 | // checks to see whether player or dealer has high hand 43 | } 44 | 45 | const ante = () => { 46 | // allows players to ante 47 | } 48 | 49 | const playGame = () => { 50 | // starts game and plays one hand 51 | } 52 | 53 | playGame(); 54 | -------------------------------------------------------------------------------- /pomodoro/pomodoro.js: -------------------------------------------------------------------------------- 1 | 2 | let now = new Date().getTime(); 3 | -------------------------------------------------------------------------------- /rockPaperScissors/rock-paper-scissors.js: -------------------------------------------------------------------------------- 1 | const getUserChoice = userInput => { 2 | userInput = userInput.toLowerCase('Please enter a selection:'); 3 | if (userInput === 'rock' || 'paper' || 'scissors') { 4 | return userInput; 5 | } else { 6 | console.log('please enter a valid selection'); 7 | } 8 | } 9 | 10 | const getComputerChoice = () => { 11 | let compSelection = Math.floor(Math.random() * 2) === 0; 12 | if ( compSelection === 0) { 13 | return 'rock'; 14 | } else if (compSelection === 1) { 15 | return 'paper'; 16 | } else { 17 | return 'scissors'; 18 | } 19 | } 20 | 21 | const determineWinner = (userChoice, computerChoice) => { 22 | if (userChoice === 'bomb') { 23 | return `User wins!`; // secret "cheat code" allows user to always win 24 | } 25 | if (userChoice === computerChoice) { 26 | return `It's a tie!`; 27 | } else if (userChoice === 'rock') { 28 | if (computerChoice === 'scissors') { 29 | return `User wins!`; 30 | } else { 31 | return `Computer wins!`; 32 | } 33 | } else if (userChoice === 'paper') { 34 | if (computerChoice === 'scissors') { 35 | return `Computer wins!`; 36 | } else { 37 | return `User wins!`; 38 | } 39 | } else if (userChoice === 'scissors') { 40 | if (computerChoice === 'rock') { 41 | return `Computer wins!`; 42 | } else { 43 | return `User wins!`; 44 | } 45 | } 46 | } 47 | 48 | const playGame = () => { 49 | let userChoice = getUserChoice('scissors'); 50 | console.log(`User: ${userChoice}`); 51 | let computerChoice = getComputerChoice(); 52 | console.log(`Computer: ${computerChoice}`); 53 | console.log(determineWinnter(userChoice, computerChoice)); 54 | } 55 | 56 | playGame(); 57 | -------------------------------------------------------------------------------- /scrabble/scrabble.js: -------------------------------------------------------------------------------- 1 | const letterValues = { 'A' : 1, 'E' : 1, 'I' : 1, 'O' : 1, 'U' : 1, 'L' : 1, 'N' : 1, 'S' : 1, 'T' : 1, 'R' : 1, 2 | 'D' : 2, 'G' : 2, 3 | 'B' : 3, 'C' : 3, 'M' : 3, 'P' : 3, 4 | 'F' : 4, 'H' : 4, 'V' : 4, 'W' : 4, 'Y' : 4, 5 | 'K' : 5, 6 | 'J' : 8, 'X' : 8, 7 | 'Q' : 10, 'Z' : 10, 8 | 'Blank' : 0 }; 9 | 10 | const specialSquares = { '2L' : [[0,3],[0,11],[3,0],[11,0],[3,14],[11,14],[14,3],[14,11]], 11 | '3L' : [], 12 | '2W' : [], 13 | '3W' : [[0,0],[0,7],[0,14],[7,0],[7,7],[7,14],[0,14],[7,14],[3,14]] }; 14 | 15 | Array.matrix = function(numrows, numcols, initial){ 16 | let arr = []; 17 | for (var i = 0; i < numrows; ++i){ 18 | var columns = []; 19 | for (var j = 0; j < numcols; ++j){ 20 | columns[j] = initial; 21 | } 22 | arr[i] = columns; 23 | } 24 | return arr; 25 | } 26 | 27 | const specialSquares = () => { 28 | // creates locations for double letter, triple letter, double word, and triple word scores 29 | } 30 | 31 | let originalBoard = Array.matrix(15,15,0); 32 | let playingBoard; 33 | 34 | const startingLetters = { 'Blank' : 2, 35 | 'E' : 12, 36 | 'A' : 9, 37 | 'I' : 9, 38 | 'O' : 8, 39 | 'N' : 6, 40 | 'R' : 6, 41 | 'T' : 6, 42 | 'L' : 4, 43 | 'S' : 4, 44 | 'U' : 4, 45 | 'D' : 4, 46 | 'G' : 3, }; 47 | let remainingLetters; 48 | let currentScore = { 'user1' : 0, 49 | 'user2' : 0 }; 50 | 51 | const printBoard = () => { 52 | // prints current board to console 53 | } 54 | 55 | const whoStarts = () => { 56 | // randomly chooses starting player 57 | return Math.floor(Math.random() * 2); 58 | } 59 | 60 | const switchUser = () => { 61 | // changes user between turns 62 | } 63 | 64 | const userPass = () => { 65 | // allows user to pass, missing one turn 66 | } 67 | 68 | const dealLetters = () => { 69 | // randomly deals five letter from letters array to each player (if available) 70 | // returns object with five letters for each player 71 | } 72 | 73 | const printLetters = (user) => { 74 | // prints current user's letters 75 | } 76 | 77 | const lettersRemain = () => { 78 | // returns true if letters remain in remainingLetters, false otherwise 79 | } 80 | 81 | const playLetters = (user, word, location) => { 82 | // allows player to play letters 83 | // blank tiles are treated as wildcards 84 | // increments user score 85 | if (specialSquare) { 86 | // calculate score based on special squares 87 | } 88 | validWord(); // checks whether word is in dictionary 89 | // removes played letters from remainingLetters object 90 | } 91 | 92 | const validWord = () => { 93 | // checks words against Oxford Dictionary API - https://www.npmjs.com/package/oxford-dictionary-api 94 | // returns true for valid word, false otherwise 95 | } 96 | 97 | const startGame = () => { 98 | remainingLetters = startingLetters; 99 | let playingBoard = originalBoard; 100 | dealLetters(); 101 | printBoard(); 102 | printLetters(user); 103 | while (lettersRemain()) { 104 | playLetters(user); 105 | if (!userPass()) { 106 | switchUser(); 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /simon/simon.js: -------------------------------------------------------------------------------- 1 | const notes = { 'E4' : [329.63, 'blue'] // E-note (blue, lower right) 2 | 'C#4' : [277.18, 'yellow'] // C♯-note (yellow, lower left) 3 | 'A3' : [220.00, 'red'] // A-note (red, upper right) 4 | 'E3' : [164.81, 'green'] // E-note (green, upper left, an octave lower than blue) 5 | } 6 | 7 | let computerSequence = { } 8 | 9 | const playNote = (note) => { 10 | let context = new window.webkitAudioContext(); // create new audio context 11 | let osc = context.createOscillator(); // create new oscillator 12 | osc.frequency.value = notes[note]; 13 | osc.connect(context.destination); 14 | osc.start(0); 15 | } 16 | 17 | const playSequence = (level) => { 18 | // returns random sequence of notes, with length based on level 19 | switch (level) { 20 | case 1: 21 | console.log(`Level is ${level}`); 22 | return randomNote(); 23 | break; 24 | case 2: 25 | console.log(`Level is ${level}`); 26 | break; 27 | case 3: 28 | console.log(`Level is ${level}`); 29 | break; 30 | case 4: 31 | console.log(`Level is ${level}`); 32 | break; 33 | case 5: 34 | console.log(`Level is ${level}`); 35 | break; 36 | case 6: 37 | console.log(`Level is ${level}`); 38 | break; 39 | case 7: 40 | console.log(`Level is ${level}`); 41 | break; 42 | case 8: 43 | console.log(`Level is ${level}`); 44 | break; 45 | case 9: 46 | console.log(`Level is ${level}`); 47 | break; 48 | case 10: 49 | console.log(`Level is ${level}`); 50 | break; 51 | default: 52 | console.log('Need a level betwen 1 and 10'); 53 | } 54 | } 55 | 56 | const randomNote = (object) => { 57 | // returns pseudo-random number between 1 and 4 58 | let result; 59 | let count = 0; 60 | for (var prop in obj) 61 | if (Math.random() < 1/++count) 62 | computerSequence[result] = prop; 63 | return computerSequence; 64 | } 65 | 66 | const userGuess = () => { 67 | // allows user to press buttons replicating computer sequence 68 | // returns true if correct, false otherwise 69 | } 70 | 71 | const playGame = (level=1) => { 72 | // starts and plays game 73 | if (userGuess()) { 74 | level += 1; 75 | if (level > 10) { 76 | console.log('You won!'); 77 | playGame(); 78 | } 79 | playGame(level); 80 | } else { 81 | playGame(); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /snakeGame/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Snake 7 | 8 | 9 | 10 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /snakeGame/sketch.js: -------------------------------------------------------------------------------- 1 | let snake; 2 | let cols; 3 | let rows; 4 | let food; 5 | let lostTail = false; 6 | const SCL = 20; 7 | 8 | function setUp(){ 9 | createCanvas(600, 600); 10 | cols = floor( width/SCL ); 11 | rows = floor( height/SCL ); 12 | pickFoodLocation(); 13 | snake = new Snake; 14 | frameRate(10); 15 | } 16 | 17 | function pickFoodLocation(){ 18 | food = createVector( floor(random(cols)), floor(random(rows) )); 19 | food.mult( SCL ); 20 | } 21 | 22 | function draw(){ 23 | background(51); 24 | if (eatsFood( food )){ 25 | pickFoodLocation(); 26 | } 27 | fill( 255, 0, 0 ); 28 | rect( food.x, food.y, SCL, SCL ); 29 | snake.update(); 30 | snake.show(); 31 | 32 | textSize(32); 33 | text( snake.total, 10, 30 ); 34 | if ( snake.losesTail() ) { 35 | lostTail = true; 36 | } 37 | 38 | if (snake.total === 0 && lostTail) { 39 | text( “Start Over”, 10, 60 ); 40 | } 41 | } 42 | 43 | function keyPressed(){ 44 | if (keyCode === UP_ARROW) { 45 | moveDir(0, -1); 46 | } 47 | else if (keyCode === DOWN_ARROW) { 48 | moveDir(0, 1); 49 | } 50 | else if (keyCode === LEFT_ARROW) { 51 | moveDir(-1, 0); 52 | } 53 | else if (keyCode === RIGHT_ARROW) { 54 | moveDir(1, 0); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /snakeGame/snake.js: -------------------------------------------------------------------------------- 1 | class Snake { 2 | constructor() { 3 | this.pos = createVector( 0,0 ); 4 | this.speedX = SCL; 5 | this.speedY = 0; 6 | this.total = 0; 7 | this.tail = []; 8 | } 9 | 10 | moveDir(xDir, yDir){ 11 | this.xSpeed = xDir * SCL; 12 | this.ySpeed = yDir * SCL; 13 | 14 | } 15 | 16 | eatsFood(foodPos){ 17 | var d = dist(this.pos.x, this.pos.y, foodPos.x, foodPos.y); 18 | if (d < 1) { 19 | this.total++; 20 | return true; 21 | } else { 22 | return false; 23 | } 24 | } 25 | 26 | losesTail() { 27 | for ( var i = 0; i < this.tail.length; i++) { 28 | const d = this.pos.dist( this.tail[i] ); 29 | if ( d < 1 ) { 30 | this.total = 0; 31 | this.tail = []; 32 | return true; 33 | } 34 | } 35 | return false; 36 | } 37 | 38 | update(){ 39 | if (this.total === this.tail.length) { 40 | for (var i = 0; i < this.tail.length - 1; i++) { 41 | this.tail[ i ] = this.tail[ i + 1 ]; 42 | } 43 | } 44 | const tempX = this.pos.x + this.xSpeed; 45 | const tempY = this.pos.y + this.ySpeed; 46 | this.pos.x = constrain(tempX, 0, width - scl); 47 | this.pos.y = constrain(tempY, 0, height - scl); 48 | if (this.total > 0) { 49 | this.tail[ this.total - 1 ] = this.pos.copy(); 50 | } 51 | } 52 | 53 | show(){ 54 | fill(255); 55 | rect(this.pos.x, this.pos.y, SCL, SCL); 56 | for (var i = 0; i < this.tail.length; i++) { 57 | rect( this.tail[i].x, this.tail[i].y, this.size, this.size ); 58 | } 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /stockTrader/stock-trader.js: -------------------------------------------------------------------------------- 1 | let userFunds = 100.0; // user starts out with $100 to trade 2 | let portfolio = { 'aapl': 10, // user starts with one stock 3 | 'value': function() { 4 | let sum = 0; 5 | for (var el in obj) { 6 | if (this.hasOwnProperty(el) ) { 7 | sum += parseFloat(this[el]); 8 | } 9 | } 10 | return sum; } 11 | }; 12 | 13 | constDisplayFunds() { 14 | // returns current uninvested money along with invested value 15 | } 16 | 17 | constDisplayChanges() { 18 | // displays user losses or gains 19 | } 20 | 21 | const userFundChoice() { 22 | // ask user if they want to buy stocks or mutual funds 23 | } 24 | 25 | const userTimeChoice(startDate='current') { 26 | // allows user to select historical data or current 27 | } 28 | 29 | const showStocks(choice_of_type) { 30 | // show list of ten stocks or mutual funds 31 | } 32 | 33 | const getUserSymbol() { 34 | try { 35 | // get user input for stock symbol 36 | let symbol = prompt("Please enter a stock of your choice"); 37 | } 38 | catch(error) { 39 | console.log(error); 40 | alert('Please enter a valid stock symbol'); 41 | userSymbol(); 42 | } 43 | displayCurrentPrice(symbol); 44 | return symbol; 45 | } 46 | 47 | const displayCurrentPrice(symbol) { 48 | // uses IEX for current stock prices - https://iextrading.com/developer/docs/ 49 | let getRequest = `GET /stock/${symbol}/company`; 50 | let pricePerShare = getRequest.price; 51 | return pricePerShare; 52 | } 53 | 54 | const displayDayChart() { 55 | // displays current days price in line graph 56 | } 57 | 58 | const displayGainLoss() { 59 | // displays gain or loss in users stocks 60 | } 61 | 62 | const buyStock(dollarAmount, shares) { 63 | if (dollarAmount >= userFunds) { 64 | alert('Dollar amount exceeds funds'); 65 | break; 66 | } 67 | if (shares * displayCurrentPrice(getUserSymbol()) >= userFunds) { 68 | alert('Dollar amount exceeds funds'); 69 | break; 70 | } 71 | if (shares % 1 !== 0) { // shares must be a whole number 72 | alert('Number of shares must be a whole number'); 73 | break; 74 | } 75 | // allows user to buy a dollar amount or number of shares 76 | let currentPrice = displayCurrentPrice(symbol); 77 | if (args[0] !== undefined) { 78 | userFunds -= dollarAmount; 79 | shares = dollarAmount / displayCurrentPrice(symbol); 80 | portfolio['symbol'] = shares; // add stock to user's portfolio with current price 81 | } else { 82 | userFunds -= shares * currentPrice; 83 | portfolio['symbol'] = shares; // add stock to user's portfolio with current price 84 | } 85 | } 86 | 87 | const sellStock(dollarAmount, shares) { 88 | // allows user to sell a dollar amount or number of shares 89 | } 90 | -------------------------------------------------------------------------------- /ticTacToe/tic-tac-toe.js: -------------------------------------------------------------------------------- 1 | let board = [ [' ', ' ', ' '], 2 | [' ', ' ', ' '], 3 | [' ', ' ', ' '] ]; 4 | 5 | let currentPlayer; 6 | 7 | const printBoardPositions = () => { 8 | console.log('Here is the current board...'); 9 | // prints positions for user 10 | let currentNumber = 1; 11 | for (let i = 0; i < board.length; i++) { 12 | for (let j = 0; j < board[i].length; j++) { 13 | board[i][j] = currentNumber; 14 | currentNumber += 1; 15 | } 16 | } 17 | console.log(board); 18 | } 19 | 20 | const markerExists = () => { 21 | // checks to see if a marker has already been placed 22 | } 23 | 24 | const placeMarker = (playerMarker) => { 25 | let position = prompt('Please enter the position you would like to place your marker, 1-9'); 26 | // adds X or O to board at specified location 27 | for (let i = 0; i < board.length; i++) { 28 | for (let j = 0; j < board[i].length; j++) { 29 | if (board[i][j] === position && !markerExists()) { 30 | currentPlayer = board[i][j]; 31 | } else { 32 | placeMarker(); 33 | } 34 | } 35 | } 36 | } 37 | 38 | const switchPlayer = () => { 39 | if (currentPlayer === 'X') { 40 | currentPlayer = 'O'; 41 | } else { 42 | currentPlayer = 'X'; 43 | } 44 | } 45 | 46 | const gameWon = () => { 47 | // checks to see if any markers span three consecutive cells 48 | // returns true if won, false otherwise 49 | } 50 | 51 | const playGame = () => { 52 | let startPlayer = Math.floor(Math.random()) > 0.5 ? 'X' : 'O'; 53 | currentPlayer = startPlayer; 54 | while (!gameWon()) { 55 | printBoardPositions(); 56 | placeMarker(currentPlayer); 57 | switchPlayer(); 58 | } 59 | console.log(`Player ${currentPlayer} won!); 60 | } 61 | 62 | playGame(); 63 | 64 | 65 | -------------------------------------------------------------------------------- /toDo/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Todo App 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /toDo/script.js: -------------------------------------------------------------------------------- 1 | class Model { 2 | constructor() {} 3 | } 4 | 5 | class View { 6 | constructor() {} 7 | } 8 | 9 | class Controller { 10 | constructor(model, view) { 11 | this.model = model 12 | this.view = view 13 | } 14 | } 15 | 16 | const app = new Controller(new Model(), new View()) 17 | -------------------------------------------------------------------------------- /toDo/style.css: -------------------------------------------------------------------------------- 1 | *, 2 | *::before, 3 | *::after { 4 | box-sizing: border-box 5 | } 6 | 7 | html { 8 | font-family: sans-serif; 9 | font-size: 1rem; 10 | color: #444; 11 | } 12 | 13 | #root { 14 | max-width: 450px; 15 | margin: 2rem auto; 16 | padding: 0 1rem; 17 | } 18 | 19 | form { 20 | display: flex; 21 | margin-bottom: 2rem; 22 | } 23 | 24 | [type="text"], 25 | button { 26 | display: inline-block; 27 | -webkit-appearance: none; 28 | padding: .5rem 1rem; 29 | font-size: 1rem; 30 | border: 2px solid #ccc; 31 | border-radius: 4px; 32 | } 33 | 34 | button { 35 | cursor: pointer; 36 | background: #007bff; 37 | color: white; 38 | border: 2px solid #007bff; 39 | margin: 0 .5rem; 40 | } 41 | 42 | [type="text"] { 43 | width: 100%; 44 | } 45 | 46 | [type="text"]:active, 47 | [type="text"]:focus { 48 | outline: 0; 49 | border: 2px solid #007bff; 50 | } 51 | 52 | [type="checkbox"] { 53 | margin-right: 1rem; 54 | font-size: 2rem; 55 | } 56 | 57 | h1 { 58 | color: #222; 59 | } 60 | 61 | ul { 62 | padding: 0; 63 | } 64 | 65 | li { 66 | display: flex; 67 | align-items: center; 68 | padding: 1rem; 69 | margin-bottom: 1rem; 70 | background: #f4f4f4; 71 | border-radius: 4px; 72 | } 73 | 74 | li span { 75 | display: inline-block; 76 | padding: .5rem; 77 | width: 250px; 78 | border-radius: 4px; 79 | border: 2px solid transparent; 80 | } 81 | 82 | li span:hover { 83 | background: rgba(179, 215, 255, 0.52); 84 | } 85 | 86 | li span:focus { 87 | outline: 0; 88 | border: 2px solid #007bff; 89 | background: rgba(179, 207, 255, 0.52) 90 | } 91 | -------------------------------------------------------------------------------- /twitterClone/twitter-clone.js: -------------------------------------------------------------------------------- 1 | 2 | --------------------------------------------------------------------------------