Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE HTML>
- <html lang="en-us">
- <head>
- <meta charset="utf-8">
- <meta name="author" content="Artem Karpikov">
- <title>A person’s score in the game of 21 </title>
- <script>
- /*The function must have this header: function twentyOne(hand)*/
- /*Input: No input from user.
- Process: Return the string "bust", otherwise the function must return the sum.
- Output: Displays the sum of the array or the message "bust".
- */
- // This function calls the twentyOne(hand) function.
- function output()
- {
- var result = twentyOne();
- document.getElementById('outputDiv1').innerHTML = result;
- }
- function twentyOne(hand)
- {
- var s = 0;
- var max = 10;
- var min = 1;
- var hand = new Array(Math.floor(Math.random() * (max - min + 1) ) + min);
- // For each index in the array named hand,
- for (var i = 0; i < hand.length; i++) {
- // store the random value in the hand.
- hand[i] = parseInt([Math.floor(Math.random() * (max - min + 1) ) + min]);
- s += hand[i];
- }
- if (s > 21 ){
- return "bust";
- }
- else {
- return s; // return the sum
- }
- }
- </script>
- </head>
- <body>
- <h1> A person’s score in the game of 21</h1>
- <h2>Click the compute functions button to return the sum of the random array not bigger than 21</h2>
- <button type="button" onclick="output()">Compute Functions</button>
- <div id="outputDiv1"></div>
- </body>
- </html>
Add Comment
Please, Sign In to add comment