
Cut And
Paste Code For Lesson 9
This page is still under construction, check back
later!
This week we learn how to create random numbers and events:
<!DOCTYPE html>
<html>
<body>
<p>I'm thinking
of a number between 1 and 100.</p>
<p>What is your guess?</p>
<button
onclick="myFunction()">Click Here To Enter Your Number</button>
<br><br><br>
<button
onclick="myFunction2()">My number was:
<p id="demo"></p>
<script>
function myFunction() {
var person = prompt("Enter your guess, if you
dare!", "");
if (person != null) {
document.getElementById("demo").innerHTML
=
"How could you have
thought " + person + "? I was thinking:";
myFunction2()
}
}
function
myFunction2() {
var x = document.getElementById("demo")
x.innerHTML
= Math.floor((Math.random() * 100) + 1);
}
</script>
</body>
</html>