Locked lesson.
About this lesson
Let's create a fill-out form to enter our answers.
Exercise files
Download this lesson’s related exercise files.
Create the Fill-Out Form.docx59.3 KB Create the Fill-Out Form - Solution.docx
59.3 KB
Quick reference
Create the Fill-Out Form
Let's generate some random numbers and create a fill-out form.
When to use
We'll need to generate random numbers every time the app runs.
Instructions
To create a random number with JavaScript (between 1 and 10):
document.write(Math.floor(Math.random() * 10) + 1);
Our program so far looks like this:
<html>
<head>
<title>Addition Flashcards</title>
<script>
var number1 = Math.floor((Math.random() * 10) + 1);
var number2 = Math.floor((Math.random() * 10) + 1);
var correctAnswer = number1 + number2;
</script>
</head>
<body>
<h1>Addition Flashcards</h1>
<h1>
<script>
document.write(number1 + " + " + number2);
</script>
</h1>
<input id="answer">
<button type="button">Submit Answer</button>
<button type="button">Next Card</button>
</body>
</html>
Hints & tips
- Random numbers are a little harder in JavaScript than in other programming languages
- document.write(Math.floor(Math.random() * 10) + 1);
Lesson notes are only available for subscribers.