Working with checkboxes in JavaScript

Now we will learn how to work with checkboxes. The checkbox can be in two states: checked and unchecked.

The checkbox is created like this:

html<input type="checkbox" id="elem">

To make a checkbox checked, you need to write the attribute checked:

html<input type="checkbox" checked id="elem">

For example, let's find out the state of our checkbox:

javascriptlet elem = document.querySelector('#elem');
console.log(elem.checked);
Задание 1

Given a checkbox and two buttons. By clicking on the first button, set the checkbox to the checked state, and by clicking on the second - to the unchecked state.

Задание 2

Given a checkbox, a button and a paragraph. On clicking the button, if the checkbox is checked, output the word 'hello' into the paragraph, and if the checkbox is not checked, then the word 'bye'.