|
1332 | 1332 | " ", |
1333 | 1333 | " // Only change code above this line.", |
1334 | 1334 | " ", |
1335 | | - " $(\".logger\").html(\"\");", |
1336 | | - " $(\".logger\").html(\"Not A Win\")", |
1337 | 1335 | " ", |
1338 | 1336 | " if (slotOne !== undefined && slotTwo !== undefined && slotThree !== undefined) {", |
1339 | 1337 | " $(\".logger\").html(slotOne + \" \" + slotTwo + \" \" + slotThree);", |
1340 | 1338 | " }", |
| 1339 | + " ", |
| 1340 | + " ", |
| 1341 | + " $(\".logger\").append(\" Not A Win\")", |
1341 | 1342 | " return [slotOne, slotTwo, slotThree];", |
1342 | 1343 | " }", |
1343 | 1344 | "", |
|
1459 | 1460 | "title": "Add your JavaScript Slot Machine Slots", |
1460 | 1461 | "description": [ |
1461 | 1462 | "Now that our slots will each generate random numbers, we need to check whether they've all returned the same number.", |
1462 | | - "If they have, we should notify our user that they've won.", |
1463 | | - "Otherwise, we should return <code>null</code>, which is a JavaScript data structure that means nothing.", |
1464 | | - "If all three numbers match, we should return the number that we have in three of slots or leave it as <code>null</code>.", |
1465 | | - "Let's create an <code>if statement</code> with multiple conditions in order to check whether all numbers are equal.", |
1466 | | - "<code>if (slotOne !== slotTwo || slotTwo !== slotThree) {</code>", |
| 1463 | + "If they have, we should notify our user that they've won and we should return <code>null</code>.", |
| 1464 | + "<code>null</code> is a JavaScript data structure that means nothing.", |
| 1465 | + "The user wins when all the three numbers match. Let's create an <code>if statement</code> with multiple conditions in order to check whether all numbers are equal.", |
| 1466 | + "<code>if(slotOne === slotTwo && slotTwo === slotThree){</code>", |
1467 | 1467 | "<code> return null;</code>", |
1468 | | - "<code>}</code>" |
| 1468 | + "<code>}</code>", |
| 1469 | + "Also, we need to show the user that he has won the game when he gets the same number in all the slots.", |
| 1470 | + "If all three numbers match, we should also set the text <code>\"It's A Win\"</code> to the element with class <code>logger</code>." |
1469 | 1471 | ], |
1470 | 1472 | "tests": [ |
1471 | 1473 | "assert((function(){var data = runSlots();return data === null || data.toString().length === 1;})(), 'If all three of our random numbers are the same we should return that number. Otherwise we should return <code>null</code>.')" |
|
1483 | 1485 | " slotTwo = Math.floor(Math.random() * (3 - 1 + 1)) + 1;", |
1484 | 1486 | " slotThree = Math.floor(Math.random() * (3 - 1 + 1)) + 1;", |
1485 | 1487 | " ", |
1486 | | - " $(\".logger\").html(\"\");", |
1487 | | - " $(\".logger\").html(\"Not A Win\");", |
1488 | 1488 | " ", |
1489 | 1489 | " // Only change code below this line.", |
1490 | 1490 | " ", |
1491 | 1491 | " ", |
1492 | 1492 | " ", |
1493 | 1493 | " // Only change code above this line.", |
1494 | 1494 | " ", |
1495 | | - " if (slotOne !== undefined && slotTwo !== undefined && slotThree !== undefined) {", |
1496 | | - " $(\".logger\").html(slotOne);", |
1497 | | - " $(\".logger\").append(\" \" + slotTwo);", |
1498 | | - " $(\".logger\").append(\" \" + slotThree);", |
| 1495 | + " if(slotOne !== undefined && slotTwo !== undefined && slotThree !== undefined){", |
| 1496 | + " $(\".logger\").html(slotOne + \" \" + slotTwo + \" \" + slotThree);", |
1499 | 1497 | " }", |
| 1498 | + " ", |
| 1499 | + " $(\".logger\").append(\" Not A Win\");", |
| 1500 | + " ", |
1500 | 1501 | " return [slotOne, slotTwo, slotThree];", |
1501 | 1502 | " }", |
1502 | 1503 | "", |
|
1621 | 1622 | "Let's use the jQuery <code>selector</code> <code>$(\".slot\")</code> to select all of the slots.", |
1622 | 1623 | "Once they are all selected, we can use <code>bracket notation</code> to access each individual slot:", |
1623 | 1624 | "<code>$($(\".slot\")[0]).html(slotOne);</code>", |
1624 | | - "This jQuery will select the first and update the slot's HTML to display the correct number.", |
| 1625 | + "This jQuery will select the first slot and update it's HTML to display the correct number.", |
1625 | 1626 | "Use the above selector to display each number in its corresponding slot." |
1626 | 1627 | ], |
1627 | 1628 | "tests": [ |
|
1641 | 1642 | " slotTwo = Math.floor(Math.random() * (3 - 1 + 1)) + 1;", |
1642 | 1643 | " slotThree = Math.floor(Math.random() * (3 - 1 + 1)) + 1;", |
1643 | 1644 | " ", |
1644 | | - " $(\".logger\").html(\"\");", |
1645 | | - " $(\".logger\").html(\"Not A Win\")", |
1646 | 1645 | " ", |
1647 | 1646 | " // Only change code below this line.", |
1648 | 1647 | " ", |
|
1651 | 1650 | " // Only change code above this line.", |
1652 | 1651 | " ", |
1653 | 1652 | " if (slotOne === slotTwo && slotTwo === slotThree) {", |
1654 | | - " return slotOne;", |
| 1653 | + " $(\".logger\").html(\" It's A Win\")", |
| 1654 | + " return null;", |
1655 | 1655 | " }", |
1656 | 1656 | " ", |
1657 | | - " if (slotOne !== undefined && slotTwo !== undefined && slotThree !== undefined) {", |
1658 | | - " $(\".logger\").html(slotOne);", |
1659 | | - " $(\".logger\").append(\" \" + slotTwo);", |
1660 | | - " $(\".logger\").append(\" \" + slotThree);", |
| 1657 | + " if(slotOne !== undefined && slotTwo !== undefined && slotThree !== undefined){", |
| 1658 | + " $(\".logger\").html(slotOne + \" \" + slotTwo + \" \" + slotThree);", |
1661 | 1659 | " }", |
1662 | 1660 | " ", |
| 1661 | + " $(\".logger\").append(\" Not A Win\");", |
| 1662 | + " ", |
| 1663 | + " ", |
1663 | 1664 | " return [slotOne, slotTwo, slotThree];", |
1664 | 1665 | " }", |
1665 | 1666 | "", |
|
1810 | 1811 | " slotTwo = Math.floor(Math.random() * (3 - 1 + 1)) + 1;", |
1811 | 1812 | " slotThree = Math.floor(Math.random() * (3 - 1 + 1)) + 1;", |
1812 | 1813 | " ", |
1813 | | - " $('.logger').html('');", |
1814 | | - " $('.logger').html('Not A Win');", |
1815 | 1814 | " ", |
1816 | 1815 | " // Only change code below this line.", |
1817 | 1816 | " ", |
|
1820 | 1819 | " // Only change code above this line.", |
1821 | 1820 | " ", |
1822 | 1821 | " if (slotOne === slotTwo && slotTwo === slotThree) {", |
1823 | | - " return slotOne;", |
| 1822 | + " $('.logger').html(\"It's A Win\");", |
| 1823 | + " return null;", |
1824 | 1824 | " }", |
1825 | 1825 | " ", |
1826 | | - " if (slotOne !== undefined && slotTwo !== undefined && slotThree !== undefined) {", |
1827 | | - " $('.logger').html(slotOne);", |
1828 | | - " $('.logger').append(' ' + slotTwo);", |
1829 | | - " $('.logger').append(' ' + slotThree);", |
| 1826 | + " if(slotOne !== undefined && slotTwo !== undefined && slotThree !== undefined){", |
| 1827 | + " $(\".logger\").html(slotOne + \" \" + slotTwo + \" \" + slotThree);", |
1830 | 1828 | " }", |
1831 | 1829 | " ", |
| 1830 | + " $('.logger').append(\" Not A Win\");", |
| 1831 | + " ", |
1832 | 1832 | " return [slotOne, slotTwo, slotThree];", |
1833 | 1833 | " }", |
1834 | 1834 | "", |
|
0 commit comments