Huffman Coding
Writing Programs in your Webpage
The Guess Game (Using Functions)
Writing Code to Explore Number Bases
<!-- Version 0 PageProgram.html -->
<html>
<head>
<script>
function clearScreen()
{
document.getElementById("disp").innerHTML = "";
}
function print(stuffYouAreGoingToSendMe)
{
document.getElementById("disp").innerHTML += stuffYouAreGoingToSendMe + "<br />";
}
function action()
{
// clearScreen();
var number = 78;
var guess = 50;
print("number: " + number + " guess: " + guess);
}
</script>
</head>
<body>
<input type="button" value="Action"
onclick="action()" />
<div id="disp"></div>
</body>
</html>
Declare this variable:
var counter = 1;
action() content:
var number = 8;
var guess = Math.floor(Math.random() * 10) + 1;
if(number != guess)
{
print("Guess # " + counter + ": number: " + number + " guess: " + guess);
counter++
}
else {
print("You got it on guess #" + counter + "! The number was " + number + ".")
counter = 1;
}
action() content:
clearScreen();
const TOD = ["morning", "afternoon", "evening", "night"];
var tm = TOD[Math.floor(Math.random()*TOD.length)];
print ("Good " + tm + ", nerd !");