1.1 Buttons and Inputs
In this exercise, you implement some simple features using the app template. The goal is to become familiar with HTML and JavaScript as well as with the app template.
Last updated
Was this helpful?
In this exercise, you implement some simple features using the app template. The goal is to become familiar with HTML and JavaScript as well as with the app template.
Last updated
Was this helpful?
Make a copy of the for each of the tasks below, and write the necessary code with JavaScript and HTML to solve the tasks below.
Add the necessary code to write the text "Hello World!" to the console!
Solution:
Allow the user to enter a number. Write a program that determines whether that number is odd or even when the user presses a button. Print the result to the console!
Solution:
Allow the user to enter two numbers. Write a program that adds both values together when the user presses a button. Print the result to the console!
Solution:
Allow the user to enter a number and interpret the number as the radius of a circle. Write a program that calculates the area and circumference of that circle and prints it to the console!
Solution:
Solution:
Solution:
Add two input fields. When the user presses a button, take the value from the first input field to the power of the number in the second input field and print the result to the console.
Solution:
This is a little useless, but shows an important point: when someone presses the button, change the heading to the text that was entered in the input field.
Solution:
The function will truncate a number at 2 decimal points.
Re-use your program from to automatically calculate the area and circumference of circles with a radius of 1, 2, 3, and up to 100. Print all results to the console.
Make sure that your program from can handle malicious input, such as negative values for a radius. Furthermore, clean up the input field after every press of the button.
You can get a reference to an input field via its unique id with . The field value
contains the current value of an input field, which you can set to an empty string.
Check out the functionMath.pow()
to perform the calculation. The contains numerous useful functions.
To get the heading in JavaScript, add an id to it and use