This is a homework assignment for school, the basic game works fine, but I would like to display a running tab of the user's guesses each time they guess. I've read ways to do it with JQuery, but we're only supposed to use JavaScript for this assignment. Basically what I want is each time they enter a guess, it will add a line to the HTML page that says something like "You guessed #, too high/low." On the next guess, it will keep that line, and then add another. I tried messing with innerHTML to get it, but it wasn't working how I wanted it to, wouldn't keep the previous guess on the page. I'd appreciate any help. Thanks.
<html>
<head>
<title> JS guessing game </title>
<script type="text/javascript">
var ranNum;
function playGame() {
var answer;
var found = false;
var count = 10;
while ((count > 0) && (found == false)) {
answer = prompt("Guess a number between 1 and 50!");
if (answer > ranNum) { alert("Guess lower!"); }
if (answer < ranNum) { alert("Guess higher!!"); }
if (answer == ranNum) { alert("Correct!"); found = true; }
count--;
}
if (!found) { alert('Too bad, you lose ... The number was ' + ranNum); }
return found;
}
function generateRandomNumber() {
ranNum = Math.floor(Math.random() * 50) + 1;
}
window.onload = function () { generateRandomNumber(); }
</script>
</head>
<body>
<strong> Guess a random number </strong>
<input type="button" value="Play game" onclick="playGame()">
<input type="button" value="New game" onclick="generateRandomNumber()">
</body>
</html>