Wouldn't it be great if we could ask users to input some information into our web document?
And then output the information to the web document.
This unit will look at how to get information from the user and process it.
We will still use the console to help us see what is happening.
We will learn how to put information onto the web document in the next unit.
Today we will study how to:
Watch this video to see how to prompt the user for information, assign to a variable, process it and then output to the console.
A vet needs a webpage to store data on animals.
The variables required in the program are:
Set up these variables in the <script> section of your webpage.
Using prompt, ask the vet to enter the number of animals. Store the data in the variable numAnimals
Repeat this for numCats and numDogs.
Make 3 sentences using console.log to make sure everything is working ok eg:
There are 12 animals.
There are 3 cats.
There are 2 dogs.
For the variable numOthers, create a calculation to do this. The formula is:
= numAnimals - (numCats + numDogs)
Hint! You will have to understand how and when to use parseInt to do this. Watch the video again, talk to your classmates or do some research if you are not sure about this. It is a bit tricky!
Submit your solution as instructed by your tutor.