BananaMaster

5 — Adding Click Functionality to a Button in JavaScript (onclick) | JS Lessons

If you forgot something — click to go to the lesson.

Task 1.

Create two variables a = 7 and b = 9. Output the result of a multiplied by b to the console.

Task 2.

Create two variables c = 7 and d = 9. Output the result of c divided by d into a div with the class .out-2.

Task 3.

Create two variables e3 = 3 and f3 = 'Hello'. Output the result of adding these two variables into a div with the class .out-3.

Task 4.

Create two variables x1 = 'Hello' and x2 = 5. Create a div (choose any class name). Output the result of x1 - x2 into this div. Examine the result of the operation.

Task 5.

Create a paragraph with class "five". Store it in a variable a. Using innerHTML, assign the number 3.1415 inside variable a.

Task 6.

Create a div with the text "Hello". Access this div in JavaScript and replace the text "Hello" with "Pro".

Hello

Task 7.

Create a div with class "seven". Store it in a variable div7. Using innerHTML, insert the following string into it:

<img src="https://cdn4.iconfinder.com/data/icons/food-and-drink-flat-gradient/32/cone_ice_cream_food_drink_sweet-512.png" alt="">

Note: You will need to insert a string that already contains quotes. Make sure to alternate quotes properly. Wrap the entire string in single quotes.

Task 8.

Create a div and a button. When the button is clicked, execute a function that outputs the word "JavaScript" into the div.

Task 9.

Create an h2 and a button. When the button is clicked, execute a function that outputs the result of the expression "10 + 20" into the h2. The result should be "30".

Task 10.

Create an h3 and a button. When the button is clicked, execute a function that outputs the result of the expression "10 + 20" into the h3. The result should be "1020".