Guest User

Untitled

a guest
Jul 21st, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.64 KB | None | 0 0
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  6. <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css" integrity="sha384-Smlep5jCw/wG7hdkwQ/Z5nLIefveQRIY9nfy6xoR1uRYBtpZgI6339F5dgvm/e9B" crossorigin="anonymous">
  7. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.8.0/css/bootstrap-datepicker.css" />
  8. <!--<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/css/materialize.min.css" />
  9. <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700,400italic|Roboto+Mono:400,500|Material+Icons" />-->
  10.  
  11. <title>Ilan's Test</title>
  12. </head>
  13. <body>
  14.  
  15. <div class="container">
  16. <div class="row">
  17. <div class='col-sm-12' style="margin-top:10px;">
  18. <div class="form-group">
  19. <a class="btn btn-primary" id="clickme" style="color:#FFFFFF;">Generate Number</a>
  20. </div>
  21. <div id="results">
  22. </div>
  23. </div>
  24. </div>
  25. </div>
  26.  
  27. <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  28. <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/js/bootstrap.min.js" integrity="sha384-o+RDsa0aLu++PJvFqy8fFScvbHFLtbvScb8AjopnFD+iEQ7wo/CG0xlczd+2O/em" crossorigin="anonymous"></script>
  29. <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.8.0/js/bootstrap-datepicker.min.js"></script>
  30. <!--<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/js/materialize.min.js"></script>-->
  31.  
  32. <script type="text/javascript">
  33. // Declare our global variables
  34. var numcheck = new Array(); // this array will hold all generated numbers
  35. var newnum; // this is our new number placeholder
  36. var exists; // this is our boolean indicator
  37.  
  38. // On button click we run this function
  39. $('#clickme').click(function(){
  40. // Assign a new random number to our variable
  41. newnum = Math.floor(Math.random() * 11) + 1;
  42. // Itirate through our numcheck array and check if the number exists
  43. $.each(numcheck, function(i, item) {
  44.  
  45. if (item == newnum){
  46. // If the number exists, set our indicator to true, exit this loop
  47. exists = true;
  48. return false;
  49. } else {
  50. // If the number does not exist, set our indicator to true
  51. exists = false;
  52. }
  53. });
  54.  
  55. // Check our indicator what happened when we went through the array, the reason I use indicator is because if I have additional code I need this value in I can use it later
  56. if (exists == true){
  57. // If the number exists, indicate in my results log the number has been used
  58. $('#results').append('<span class="text-danger">' + newnum + ' has already been used.</span><br>');
  59. } else {
  60. // If the number does not exist in our array, indicate in the results it's a fresh number and do any custom coding needed in the below clause
  61. $('#results').append('<span class="text-success">New number generated: ' + newnum + '</span><br>');
  62. }
  63.  
  64. // Add the number to the array regardless if true or false so we can analzye its length in the future if needed, the array is our number inventory which tells us when a number has been previously used
  65. numcheck.push(newnum);
  66.  
  67. });
  68.  
  69. </script>
  70.  
  71. </body>
  72. </html>
Add Comment
Please, Sign In to add comment