Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

hello there.. i really need help through this assighnment. (Create a new file on

ID: 670853 • Letter: H

Question

hello there..

i really need help through this assighnment.

(Create a new file on your Neocities page called whilePractice.html

Create a new button for each of the following problems:

1. Prompt the user for a number. Flip a coin (use the random number generator that can only generate two numbers) that many times. When finished, report to the user how many heads and how many tails you ended up with.

2. Write a loop that continues to prompt the user for a number until they enter a negative number. When the loop ends, report how many numbers were entered (do not count the -1) and what those numbers added up to (do not count the -1).

3. Create a function that plays a guessing game with the user. The computer should choose a random number between 0 and 1000 and allow the user to guess for it until they get it correct. Give the user hints. If their number is too high, print "Too High". If their guess is too low, print "Too low". When they get the answer correct, report that it is correct and tell them how many guesses it took.)

Explanation / Answer

<html>
<head>
<script>
function HeadnTail() {
    var num= parseInt(prompt("Please enter an integer"));
   var heads = 0;
   var tails = 0;
   var rand = 0;

    if(num > 0) {
          //numbers 1 or 2; 1 - Head, 2 - Tail
         var i = 1;
          for(i =1; i <= num; i++) {
              rand = Math.floor((Math.random() * 2) + 1);
             if(rand == 1)
   heads++;
             else
   tails++;
           }
           var output = " No of times tossed: "+num+"<br/>";
           output += "Heads: "+heads+" Tails: "+tails;
             document.getElementById("dataId").innerHTML = output;
   }
}

function sum() {
   var num = 0;
   var sum = 0;
   var count = 0;  
   var str = 0;
while(num >=0) {
        num = parseInt(prompt("Please enter a postive integer to calculate sum, negative integer to quit"));
       if(num >= 0) {
               sum += num;
               count++;
               str += num+" ";
       }
}
document.getElementById("dataId").innerHTML = " No of Numbers entered : "+count+"( "+str+") <br/> Sum of numbers : "+sum;
}

function guess() {
    var rand = Math.floor((Math.random() * 1001) - 1);
    var num = 0;
    var str = ""; // rand;
    var count = 0;
    while(num != rand) {
             count++;
             num = parseInt(prompt(str+ "    Please guess number b/w (0 and 1000)"));
             if(num > rand)
                  str = "Too High";
             else if(num <rand)
                   str ="Too low";
             else {
                       document.getElementById("dataId").innerHTML = "You guessed correctly. It took "+count+" guesses";
                      break;
             }
           
    }
}
</script>
</head>
<body>
<table>
<tr><td> <button type="button"> HeadnTails</button> </td>
<td>&nbsp; &nbsp;&nbsp;<button type="button">Sum</button> </td>
<td>&nbsp;&nbsp;&nbsp; <button type="button">Guess!</button> </td>
</tr>
</table>
<br/><br/><br/>
<div id="dataId"> </div>
</body>
</html>