Guest User

Untitled

a guest
Aug 18th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. <!DOCTYPE HTML>
  2. <html lang="en-us">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="author" content="Artem Karpikov">
  6. <title>A person’s score in the game of 21 </title>
  7. <script>
  8. /*The function must have this header: function twentyOne(hand)*/
  9.  
  10. /*Input: No input from user.
  11. Process: Return the string "bust", otherwise the function must return the sum.
  12. Output: Displays the sum of the array or the message "bust".
  13. */
  14.  
  15. // This function calls the twentyOne(hand) function.
  16. function output()
  17. {
  18. var result = twentyOne();
  19. document.getElementById('outputDiv1').innerHTML = result;
  20. }
  21.  
  22. function twentyOne(hand)
  23. {
  24. var s = 0;
  25. var max = 10;
  26. var min = 1;
  27. var hand = new Array(Math.floor(Math.random() * (max - min + 1) ) + min);
  28. // For each index in the array named hand,
  29. for (var i = 0; i < hand.length; i++) {
  30. // store the random value in the hand.
  31. hand[i] = parseInt([Math.floor(Math.random() * (max - min + 1) ) + min]);
  32. s += hand[i];
  33. }
  34. if (s > 21 ){
  35. return "bust";
  36. }
  37. else {
  38. return s; // return the sum
  39. }
  40. }
  41.  
  42.  
  43. </script>
  44. </head>
  45. <body>
  46. <h1> A person’s score in the game of 21</h1>
  47. <h2>Click the compute functions button to return the sum of the random array not bigger than 21</h2>
  48. <button type="button" onclick="output()">Compute Functions</button>
  49. <div id="outputDiv1"></div>
  50. </body>
  51. </html>
Add Comment
Please, Sign In to add comment