Below is an example of a simple html page for accepting two numbers as input. Upon clicking the button, the program will show multiplication of the two inputs. The <script> section is where your Javascript code should go. The upper portion of the code (above the <script> section) is where you define the layout of the program. To test the blue colored code below, copy it onto any text editor. You can use Sublime Text or Notepad++, and save it as sample.html. Open the html file you created in any browser to see the result.
<html>
<body>
<b> <center>Sample Script Example </b></center> <br/>Enter first number:
<input type=text id=txt1 name=text1>Enter second number:
<input type=text id=txt2 name=text2>
<p id=demo></p>
<script> function myFunction() {
var mytextbox1 = document.getElementById(txt1).value; var mytextbox2 = document.getElementById(txt2).value; var result = mytextbox1 * mytextbox2; document.getElementById(demo).innerHTML = result;
}
</script>
<center><p>Click the button below</p>
<button onclick=myFunction()>Click here for multiply</button>
<br/></center>
<p id=demo></p>
</body> </html>
Once you have created the example above, you will be ready to work on the assignment.
For your first assignment, you must create your own simple JavaScript programs based on the instructions below.
- Write a JavaScript program to display the current date (i.e., day of the week, day, month, year), and current time in the following format:
Expected Output:
Today is: Friday, 6th September
2017 Current time is: 4 PM : 50 : 22
- Write a JavaScript program to enter your birthday. It should show your age in number of days.
Expected Output:
Please enter your birthday XX/XX/XXXX
You are XXXX days old
- Write a JavaScript program to find the area of a circle. The user shall input the radius.
Expected Output:
Please enter radius: XX
The area of circle is XX
- Write a JavaScript program to calculate the number of days left until your next birthday.
Expected Output:
Please enter your next birthday:
There are XX days left until your next birthday.
- Write a JavaScript program to perform the calculation, i.e., Addition, Subtraction, Multiplication, and Division, of two numbers. Expected Output:
Each instruction is worth 10 points.
For each instruction, you must name your source code as [your family name]_[instruction number].html.
For example, the program for the first instruction should be named Vasson_1.html. For the second instruction, the program source code should be named Vasson_2.html, and so on. As there are five instructions, I expect to see five individual Javascript programs.
You must put all your source code files in one zip file with the name [your family name]_CMSC202_A1.zip.
For example, Vasson_CMSC202_A1.zip
If you have any question, feel free to post it in the discussion forum. Dont hesitate to ask your classmates for help if you are stuck on an item, and feel free to help each other. However, do not copy the code of your classmates. You may also check this site for reference: http://www.w3resource.com/javascript/javascript.php
Kindly submit the assignment on time. Good luck and happy coding!
Reviews
There are no reviews yet.