├── README.md ├── css ├── noramilize.css └── style.css ├── index.html └── js └── main.js /README.md: -------------------------------------------------------------------------------- 1 | # memoryGame 2 | # How It's Made: 3 | Here is a fun little game of memory. I used a method for shuffling by pushing sections into an array and then pulling that array and placing into random sections. Afterward the user can click on each box and flip the card to hopefully match them all and then get a Game Over alert signifying the win. 4 | 5 | # Tech used: 6 | HTML, CSS, JavaScript 7 | 8 | 9 | # Lessons Learned: 10 | I learned about about event listeners and creating a game with a card shuffling method. 11 | -------------------------------------------------------------------------------- /css/noramilize.css: -------------------------------------------------------------------------------- 1 | /*! normalize.css 2012-07-07T09:50 UTC - http://github.com/necolas/normalize.css */ 2 | 3 | /* ========================================================================== 4 | HTML5 display definitions 5 | ========================================================================== */ 6 | 7 | /* 8 | * Corrects `block` display not defined in IE6/7/8/9 & FF3. 9 | */ 10 | 11 | article, 12 | aside, 13 | details, 14 | figcaption, 15 | figure, 16 | footer, 17 | header, 18 | hgroup, 19 | nav, 20 | section, 21 | summary { 22 | display: block; 23 | } 24 | 25 | /* 26 | * Corrects `inline-block` display not defined in IE6/7/8/9 & FF3. 27 | */ 28 | 29 | audio, 30 | canvas, 31 | video { 32 | display: inline-block; 33 | *display: inline; 34 | *zoom: 1; 35 | } 36 | 37 | /* 38 | * Prevents modern browsers from displaying `audio` without controls. 39 | * Remove excess height in iOS5 devices. 40 | */ 41 | 42 | audio:not([controls]) { 43 | display: none; 44 | height: 0; 45 | } 46 | 47 | /* 48 | * Addresses styling for `hidden` attribute not present in IE7/8/9, FF3, S4. 49 | * Known issue: no IE6 support. 50 | */ 51 | 52 | [hidden] { 53 | display: none; 54 | } 55 | 56 | /* ========================================================================== 57 | Base 58 | ========================================================================== */ 59 | 60 | /* 61 | * 1. Corrects text resizing oddly in IE6/7 when body `font-size` is set using 62 | * `em` units. 63 | * 2. Prevents iOS text size adjust after orientation change, without disabling 64 | * user zoom. 65 | */ 66 | 67 | html { 68 | font-size: 100%; /* 1 */ 69 | -webkit-text-size-adjust: 100%; /* 2 */ 70 | -ms-text-size-adjust: 100%; /* 2 */ 71 | } 72 | 73 | /* 74 | * Addresses `font-family` inconsistency between `textarea` and other form 75 | * elements. 76 | */ 77 | 78 | html, 79 | button, 80 | input, 81 | select, 82 | textarea { 83 | font-family: sans-serif; 84 | } 85 | 86 | /* 87 | * Addresses margins handled incorrectly in IE6/7. 88 | */ 89 | 90 | body { 91 | margin: 0; 92 | } 93 | 94 | /* ========================================================================== 95 | Links 96 | ========================================================================== */ 97 | 98 | /* 99 | * Addresses `outline` inconsistency between Chrome and other browsers. 100 | */ 101 | 102 | a:focus { 103 | outline: thin dotted; 104 | } 105 | 106 | /* 107 | * Improves readability when focused and also mouse hovered in all browsers. 108 | * people.opera.com/patrickl/experiments/keyboard/test 109 | */ 110 | 111 | a:active, 112 | a:hover { 113 | outline: 0; 114 | } 115 | 116 | /* ========================================================================== 117 | Typography 118 | ========================================================================== */ 119 | 120 | /* 121 | * Addresses font sizes and margins set differently in IE6/7. 122 | * Addresses font sizes within `section` and `article` in FF4+, Chrome, S5. 123 | */ 124 | 125 | h1 { 126 | font-size: 2em; 127 | margin: 0.67em 0; 128 | } 129 | 130 | h2 { 131 | font-size: 1.5em; 132 | margin: 0.83em 0; 133 | } 134 | 135 | h3 { 136 | font-size: 1.17em; 137 | margin: 1em 0; 138 | } 139 | 140 | h4 { 141 | font-size: 1em; 142 | margin: 1.33em 0; 143 | } 144 | 145 | h5 { 146 | font-size: 0.83em; 147 | margin: 1.67em 0; 148 | } 149 | 150 | h6 { 151 | font-size: 0.75em; 152 | margin: 2.33em 0; 153 | } 154 | 155 | /* 156 | * Addresses styling not present in IE7/8/9, S5, Chrome. 157 | */ 158 | 159 | abbr[title] { 160 | border-bottom: 1px dotted; 161 | } 162 | 163 | /* 164 | * Addresses style set to `bolder` in FF3+, S4/5, Chrome. 165 | */ 166 | 167 | b, 168 | strong { 169 | font-weight: bold; 170 | } 171 | 172 | blockquote { 173 | margin: 1em 40px; 174 | } 175 | 176 | /* 177 | * Addresses styling not present in S5, Chrome. 178 | */ 179 | 180 | dfn { 181 | font-style: italic; 182 | } 183 | 184 | /* 185 | * Addresses styling not present in IE6/7/8/9. 186 | */ 187 | 188 | mark { 189 | background: #ff0; 190 | color: #000; 191 | } 192 | 193 | /* 194 | * Addresses margins set differently in IE6/7. 195 | */ 196 | 197 | p, 198 | pre { 199 | margin: 1em 0; 200 | } 201 | 202 | /* 203 | * Corrects font family set oddly in IE6, S4/5, Chrome. 204 | * en.wikipedia.org/wiki/User:Davidgothberg/Test59 205 | */ 206 | 207 | code, 208 | kbd, 209 | pre, 210 | samp { 211 | font-family: monospace, serif; 212 | _font-family: 'courier new', monospace; 213 | font-size: 1em; 214 | } 215 | 216 | /* 217 | * Improves readability of pre-formatted text in all browsers. 218 | */ 219 | 220 | pre { 221 | white-space: pre; 222 | white-space: pre-wrap; 223 | word-wrap: break-word; 224 | } 225 | 226 | /* 227 | * Addresses CSS quotes not supported in IE6/7. 228 | */ 229 | 230 | q { 231 | quotes: none; 232 | } 233 | 234 | /* 235 | * Addresses `quotes` property not supported in S4. 236 | */ 237 | 238 | q:before, 239 | q:after { 240 | content: ''; 241 | content: none; 242 | } 243 | 244 | small { 245 | font-size: 75%; 246 | } 247 | 248 | /* 249 | * Prevents `sub` and `sup` affecting `line-height` in all browsers. 250 | * gist.github.com/413930 251 | */ 252 | 253 | sub, 254 | sup { 255 | font-size: 75%; 256 | line-height: 0; 257 | position: relative; 258 | vertical-align: baseline; 259 | } 260 | 261 | sup { 262 | top: -0.5em; 263 | } 264 | 265 | sub { 266 | bottom: -0.25em; 267 | } 268 | 269 | /* ========================================================================== 270 | Lists 271 | ========================================================================== */ 272 | 273 | /* 274 | * Addresses margins set differently in IE6/7. 275 | */ 276 | 277 | dl, 278 | menu, 279 | ol, 280 | ul { 281 | margin: 1em 0; 282 | } 283 | 284 | dd { 285 | margin: 0 0 0 40px; 286 | } 287 | 288 | /* 289 | * Addresses paddings set differently in IE6/7. 290 | */ 291 | 292 | menu, 293 | ol, 294 | ul { 295 | padding: 0 0 0 40px; 296 | } 297 | 298 | /* 299 | * Corrects list images handled incorrectly in IE7. 300 | */ 301 | 302 | nav ul, 303 | nav ol { 304 | list-style: none; 305 | list-style-image: none; 306 | } 307 | 308 | /* ========================================================================== 309 | Embedded content 310 | ========================================================================== */ 311 | 312 | /* 313 | * 1. Removes border when inside `a` element in IE6/7/8/9, FF3. 314 | * 2. Improves image quality when scaled in IE7. 315 | * code.flickr.com/blog/2008/11/12/on-ui-quality-the-little-things-client-side-image-resizing/ 316 | */ 317 | 318 | img { 319 | border: 0; /* 1 */ 320 | -ms-interpolation-mode: bicubic; /* 2 */ 321 | } 322 | 323 | /* 324 | * Corrects overflow displayed oddly in IE9. 325 | */ 326 | 327 | svg:not(:root) { 328 | overflow: hidden; 329 | } 330 | 331 | /* ========================================================================== 332 | Figures 333 | ========================================================================== */ 334 | 335 | /* 336 | * Addresses margin not present in IE6/7/8/9, S5, O11. 337 | */ 338 | 339 | figure { 340 | margin: 0; 341 | } 342 | 343 | /* ========================================================================== 344 | Forms 345 | ========================================================================== */ 346 | 347 | /* 348 | * Corrects margin displayed oddly in IE6/7. 349 | */ 350 | 351 | form { 352 | margin: 0; 353 | } 354 | 355 | /* 356 | * Define consistent border, margin, and padding. 357 | */ 358 | 359 | fieldset { 360 | border: 1px solid #c0c0c0; 361 | margin: 0 2px; 362 | padding: 0.35em 0.625em 0.75em; 363 | } 364 | 365 | /* 366 | * 1. Corrects color not being inherited in IE6/7/8/9. 367 | * 2. Corrects text not wrapping in FF3. 368 | * 3. Corrects alignment displayed oddly in IE6/7. 369 | */ 370 | 371 | legend { 372 | border: 0; /* 1 */ 373 | padding: 0; 374 | white-space: normal; /* 2 */ 375 | *margin-left: -7px; /* 3 */ 376 | } 377 | 378 | /* 379 | * 1. Corrects font size not being inherited in all browsers. 380 | * 2. Addresses margins set differently in IE6/7, FF3+, S5, Chrome. 381 | * 3. Improves appearance and consistency in all browsers. 382 | */ 383 | 384 | button, 385 | input, 386 | select, 387 | textarea { 388 | font-size: 100%; /* 1 */ 389 | margin: 0; /* 2 */ 390 | vertical-align: baseline; /* 3 */ 391 | *vertical-align: middle; /* 3 */ 392 | } 393 | 394 | /* 395 | * Addresses FF3/4 setting `line-height` on `input` using `!important` in the 396 | * UA stylesheet. 397 | */ 398 | 399 | button, 400 | input { 401 | line-height: normal; 402 | } 403 | 404 | /* 405 | * 1. Avoid the WebKit bug in Android 4.0.* where (2) destroys native `audio` 406 | * and `video` controls. 407 | * 2. Corrects inability to style clickable `input` types in iOS. 408 | * 3. Improves usability and consistency of cursor style between image-type 409 | * `input` and others. 410 | * 4. Removes inner spacing in IE7 without affecting normal text inputs. 411 | * Known issue: inner spacing remains in IE6. 412 | */ 413 | 414 | button, 415 | html input[type="button"], /* 1 */ 416 | input[type="reset"], 417 | input[type="submit"] { 418 | -webkit-appearance: button; /* 2 */ 419 | cursor: pointer; /* 3 */ 420 | *overflow: visible; /* 4 */ 421 | } 422 | 423 | /* 424 | * Re-set default cursor for disabled elements. 425 | */ 426 | 427 | button[disabled], 428 | input[disabled] { 429 | cursor: default; 430 | } 431 | 432 | /* 433 | * 1. Addresses box sizing set to content-box in IE8/9. 434 | * 2. Removes excess padding in IE8/9. 435 | * 3. Removes excess padding in IE7. 436 | * Known issue: excess padding remains in IE6. 437 | */ 438 | 439 | input[type="checkbox"], 440 | input[type="radio"] { 441 | box-sizing: border-box; /* 1 */ 442 | padding: 0; /* 2 */ 443 | *height: 13px; /* 3 */ 444 | *width: 13px; /* 3 */ 445 | } 446 | 447 | /* 448 | * 1. Addresses `appearance` set to `searchfield` in S5, Chrome. 449 | * 2. Addresses `box-sizing` set to `border-box` in S5, Chrome (include `-moz` 450 | * to future-proof). 451 | */ 452 | 453 | input[type="search"] { 454 | -webkit-appearance: textfield; /* 1 */ 455 | -moz-box-sizing: content-box; 456 | -webkit-box-sizing: content-box; /* 2 */ 457 | box-sizing: content-box; 458 | } 459 | 460 | /* 461 | * Removes inner padding and search cancel button in S5, Chrome on OS X. 462 | */ 463 | 464 | input[type="search"]::-webkit-search-cancel-button, 465 | input[type="search"]::-webkit-search-decoration { 466 | -webkit-appearance: none; 467 | } 468 | 469 | /* 470 | * Removes inner padding and border in FF3+. 471 | */ 472 | 473 | button::-moz-focus-inner, 474 | input::-moz-focus-inner { 475 | border: 0; 476 | padding: 0; 477 | } 478 | 479 | /* 480 | * 1. Removes default vertical scrollbar in IE6/7/8/9. 481 | * 2. Improves readability and alignment in all browsers. 482 | */ 483 | 484 | textarea { 485 | overflow: auto; /* 1 */ 486 | vertical-align: top; /* 2 */ 487 | } 488 | 489 | /* ========================================================================== 490 | Tables 491 | ========================================================================== */ 492 | 493 | /* 494 | * Remove most spacing between table cells. 495 | */ 496 | 497 | table { 498 | border-collapse: collapse; 499 | border-spacing: 0; 500 | } 501 | -------------------------------------------------------------------------------- /css/style.css: -------------------------------------------------------------------------------- 1 | /****************************************** 2 | /* SETUP 3 | /*******************************************/ 4 | 5 | /* Box Model Hack */ 6 | * { 7 | -moz-box-sizing: border-box; /* Firexfox */ 8 | -webkit-box-sizing: border-box; /* Safari/Chrome/iOS/Android */ 9 | box-sizing: border-box; /* IE */ 10 | } 11 | 12 | /* Clear fix hack */ /*make sure to actually use the class though- this is to make sure the section/element doesn't collapse*/ 13 | .clearfix:after { 14 | content: "."; 15 | display: block; 16 | clear: both; 17 | visibility: hidden; 18 | line-height: 0; 19 | height: 0; 20 | } 21 | .clear { 22 | clear: both; 23 | } 24 | .alignright { 25 | float: right; 26 | padding: 0 0 10px 10px; /* note the padding around a right floated image */ 27 | } 28 | .alignleft { 29 | float: left; 30 | padding: 0 10px 10px 0; 31 | } 32 | 33 | /****************************************** 34 | /* BASE STYLES 35 | /*******************************************/ 36 | body { 37 | text-align: center; 38 | color: #000; 39 | font-size: 16px; 40 | line-height: 1.4; 41 | font-family: 'Ubuntu', sans-serif; 42 | background-color: #81B3D0; 43 | } 44 | .container{ 45 | width: 90%; 46 | margin: auto; 47 | } 48 | .gameBorder{ 49 | text-align: center; 50 | } 51 | .card{ 52 | height: 100px; 53 | color: white; 54 | width: 15%; 55 | font-size: 1.8rem; 56 | border: 2px solid RGBa(255,0,0,.2); 57 | margin: 1% 8%; 58 | float: left; 59 | background-color: #DA005B; 60 | } 61 | .card:hover { 62 | border: 3px dotted green; 63 | background-color: #E5A445; 64 | } 65 | .selected{ 66 | border: 3px dotted green; 67 | background-color: #E00F71; 68 | } 69 | @media only screen and (max-width:768px){ 70 | body { 71 | font-size: .8em; 72 | } 73 | section{ 74 | font-size: .9em; 75 | } 76 | h1{ 77 | font-size: 1.5em; 78 | } 79 | .card{ 80 | width: 32%; 81 | font-size: 1.5rem; 82 | color: white; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Match 6 | 7 | 8 | 9 | 10 | 11 |
12 |

13 |
14 |

Match The Cards And You Win

15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 | 31 | 32 |
33 | 34 | 35 | -------------------------------------------------------------------------------- /js/main.js: -------------------------------------------------------------------------------- 1 | // what can the user do? 2 | // what does the user expect? 3 | // What can the user see? 4 | 5 | //click on card 6 | //add selected 7 | //if two cards have selected - see if they are a match 8 | //if they are a match add match class and remove select, so you can keep selecting 9 | $(document).ready(function(){ 10 | //memory game 11 | const app = { 12 | cards: ['JOSH', 'JOSH', 'WILL', 'WILL', 'RULE', 'RULE', 'THE', 'THE', 'WORLD', 'WORLD', 'SOON', 'SOON'], 13 | beginGame: function(){ 14 | app.shuffle(); 15 | }, 16 | 17 | shuffle: function(){ 18 | var random = 0; 19 | var temp = 0; 20 | for (i = 1; i < app.cards.length; i++) { 21 | random = Math.round(Math.random() * i); 22 | temp = app.cards[i]; 23 | app.cards[i] = app.cards[random]; 24 | app.cards[random] = temp; 25 | } 26 | app.assignCards(); 27 | console.log('Shuffled Cards: ' + app.cards); 28 | }, 29 | 30 | assignCards: function() { 31 | $('.card').each(function(index) { 32 | $(this).attr('data-card-value', app.cards[index]); 33 | }); 34 | app.clickHandlers(); 35 | }, 36 | 37 | clickHandlers: function() { 38 | $('.card').on('click', function() { 39 | $(this).html('

' + $(this).data('cardValue') + '

').addClass('selected'); 40 | app.checkForMatch(); 41 | }); 42 | }, 43 | 44 | checkForMatch: function(){ 45 | if ($('.selected').length === 2) { 46 | if ($('.selected').first().data('cardValue') == $('.selected').last().data('cardValue')) { 47 | $('.selected').each(function() { 48 | $(this).animate({ 49 | opacity: 0 50 | }).removeClass('unmatched'); 51 | }); 52 | $('.selected').each(function() { 53 | $(this).removeClass('selected'); 54 | }); 55 | app.checkForWin(); 56 | }else{ 57 | setTimeout(function() { 58 | $('.selected').each(function() { 59 | $(this).html('').removeClass('selected'); 60 | }); 61 | }, 600); 62 | } 63 | } 64 | }, 65 | 66 | checkForWin: function() { 67 | if ($('.unmatched').length === 0) { 68 | $('.container').html('

YOU WON. But most importantly it is True Josh Will Rule The World Soon!

'); 69 | } 70 | } 71 | }; 72 | 73 | app.beginGame() 74 | }); 75 | --------------------------------------------------------------------------------